public bool IsAuth(string gName)
{
_hostWebUrl = "http://myweb"; //the location where the app is being deployed
//Retreiving the current context
//Opening a current web and creating a instance
try
{
using (var context = new ClientContext(_hostWebUrl))
{
//GroupCollection siteGroups = context.Web.SiteGroups;
User user = context.Web.CurrentUser;
GroupCollection userGroups = user.Groups;
context.Load(user);
context.Load(userGroups);
context.ExecuteQuery();
foreach (Group group in userGroups)
{
//Checking the group
if (group.Title.Contains(gName))
return true;
}
}
}
catch (Exception ex)
{
string error = ex.Message;
return false;
}
return false;
}
I am calling the function like this: bool isAdmin = IsAuth("Adm");
I am getting the following error in the following line (using (var context = new ClientContext(_hostWebUrl))
):
ServerVersion = 'context.ServerVersion' threw an exception of type 'Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException'
I am getting the following error in the following line (foreach (Group group in userGroups)
):
base {System.InvalidOperationException} = {"The property or field 'CanCurrentUserEditMembership' has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested."}
Please help me resolve the error.
0 commentaires:
Enregistrer un commentaire