What SharePoint development model, framework, SDK or API is this about?
SharePoint C#
Developer environment
Visual Studio Console App
Describe the bug / error
I've used the code from the link https://docs.microsoft.com/en-us/previous-versions/office/developer/sharepoint-2010/ee538244(v=office.14) to retrieve the users from the Sharepoint Groups.
I am able to read the Group titles Successfully. However when I try to read the Users details of the group, I get an error
An unhandled exception of type 'Microsoft.SharePoint.Client.ServerUnauthorizedAccessException' occurred in Microsoft.SharePoint.Client.Runtime.dll
Additional information: Access denied. You do not have permission to perform this action or access this resource.
I have full control on the Sharepoint Site.
Steps to Reproduce:
The below piece of code executes successfully, the moment I uncomment the lines 45 to 52 I get the above mentioned Error.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint.Client;
using System.Net.Security;
using System.Net;
namespace SPGroupusers
{
class RetrieveAllUsersInGroup
{
static void Main()
{
Console.Write("Enter UserName (domain/userid): ");
string strUserName = Console.ReadLine();
Console.Write("Enter your password: ");
string pass = getPassword();
Console.WriteLine();
Console.Write("Enter Site URL: ");
string strURL = Console.ReadLine();
ClientContext ctx = new ClientContext(strURL);
ctx.Credentials = new NetworkCredential(strUserName, pass);
Web web = ctx.Web;
ctx.Load(web, w => w.Title, w => w.SiteGroups);
ctx.ExecuteQuery();
GroupCollection collGroup = ctx.Web.SiteGroups;
ctx.Load(collGroup);
GroupCollection groups = web.SiteGroups;
ctx.Load(groups, grps => grps.Include(group => group.Users));
//ctx.ExecuteQuery();
Console.WriteLine("Groups associated to the site: " + web.Title);
Console.WriteLine("Groups Count: " + groups.Count.ToString());
foreach (Group grp in groups)
{
Console.WriteLine(grp.Title);
//UserCollection collUser = grp.Users;
//ctx.Load(collUser);
//ctx.ExecuteQuery();
//foreach (User oUser in collUser)
//{
// Console.WriteLine("Group ID: {0} Group Title: {1} User: {2} Login Name: {3}",
// grp.Id, grp.Title, oUser.Title, oUser.LoginName);
//}
}
Console.Read();
}
private static string getPassword()
{
ConsoleKeyInfo key;
string pass = "";
do
{
key = Console.ReadKey(true);
// Backspace Should Not Work
if (key.Key != ConsoleKey.Backspace && key.Key != ConsoleKey.Enter)
{
pass += key.KeyChar;
Console.Write("*");
}
else
{
if (key.Key == ConsoleKey.Backspace && pass.Length > 0)
{
pass = pass.Substring(0, (pass.Length - 1));
Console.Write("\b \b");
}
}
}
// Stops Receving Keys Once Enter is Pressed
while (key.Key != ConsoleKey.Enter);
return pass;
}
}
}
Expected Behaviour:
I would like to get the list of users.
What SharePoint development model, framework, SDK or API is this about?
SharePoint C#
Developer environment
Visual Studio Console App
Describe the bug / error
I've used the code from the link https://docs.microsoft.com/en-us/previous-versions/office/developer/sharepoint-2010/ee538244(v=office.14) to retrieve the users from the Sharepoint Groups.
I am able to read the Group titles Successfully. However when I try to read the Users details of the group, I get an error
An unhandled exception of type 'Microsoft.SharePoint.Client.ServerUnauthorizedAccessException' occurred in Microsoft.SharePoint.Client.Runtime.dll
Additional information: Access denied. You do not have permission to perform this action or access this resource.
I have full control on the Sharepoint Site.
Steps to Reproduce:
The below piece of code executes successfully, the moment I uncomment the lines 45 to 52 I get the above mentioned Error.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint.Client;
using System.Net.Security;
using System.Net;
namespace SPGroupusers
{
class RetrieveAllUsersInGroup
{
static void Main()
{
Console.Write("Enter UserName (domain/userid): ");
string strUserName = Console.ReadLine();
Console.Write("Enter your password: ");
string pass = getPassword();
Console.WriteLine();
}
Expected Behaviour:
I would like to get the list of users.