I am working with Sharepoint Online and CSOM and I need to get the owner of a
specific group.
I tried to load data from ClientContext, and got a exception with the message "unknown error".
Here is the code I tried.
MC.ClientContext context = new SPClient.ClientContext("sit url");
MC.Group group = context.Web.SiteGroups.GetById("group id");
context.Load(group, x => x.Owner);
await context.ExecuteQueryAsync();
What's the correct method to get the information that I needed?
I have solved this problem by a quite strange way.
The code is something like this:
ClientContext context = new SPClient.ClientContext("sit url");
Group group = context.Web.SiteGroups.GetById("group id");
context.Load(group, x => x.Owner.PrincipalType, x => x.Owner.LoginName);
await context.ExecuteQueryAsync();
context.Load(group.Owner);
await context.ExecuteQueryAsync();
I need to call the ExecuteQuery method twice to get the object of owner.
I don't know why. But it works.
You can use GroupCollection.GetByName or GetById to retrieve an existing group and then retrieve the groupowner.
using (var context = new ClientContext("sit url"))
{
context.Credentials = credentials;
var groupOwner = context.Web.SiteGroups.GetByName("GroupName");
ctx.ExecuteQuery();
}
Related
I know this is simple but for the life of me I can't figure it out.
I'm trying to load a list of users from an Azure AD Group using the graph api. I'm almost there. I can successfully call the API, get the right group, and even see the members. But when I load that list in a list, all i see is a list of Microsoft.Graph.User. If inspect the list in code, I can drill down and see the display names but I don't know how to access them via code. there is no .displayname within the user object. Below is the code I have:
GraphServiceClient graphClient = await Authentication.SignInAndInitGraph(scope);
List<User> users = new List<User>();
var members = await graphClient.Groups["GroupID"].Members
.Request()
.GetAsync();
users.AddRange(members.CurrentPage.OfType<User>());
while(members.NextPageRequest != null)
{
members = await members.NextPageRequest.GetAsync();
users.AddRange(members.CurrentPage.OfType<User>());
}
lstUsers.DataSource = users;
What am I missing?
Convert members to list.
var members = await graphClient.Groups["group_id"].Members.Request().GetAsync();
var list = members.ToList();
foreach (Microsoft.Graph.User user in list) {
var name = user.DisplayName;
}
I want to update the "ConversationThreadId" field in a PlannerTask.
This is my code:
plannerTask = await graphClient.Planner.Tasks["XXXXXXXXX"].Request().GetAsync();
var eTagId = plannerTask.GetEtag();
plannerTask.ConversationThreadId = "YYYYYYYY";
await graphClient.Planner.Tasks[plannerTask.Id]
.Request()
.Header("Prefer", "return=representation")
.Header("If-Match", eTagId)
.UpdateAsync(plannerTask);
And it throws this error:
Message: The request is invalid: An unexpected 'StartObject' node was
found for property named 'assignedBy' when reading from the JSON
reader. A 'PrimitiveValue' node was expected.
What am I doing wrong?
Thank you
The way to get it is:
plannerTask = await graphClient.Planner.Tasks["XXXXXXXXX"].Request().GetAsync();
var eTagId = plannerTask.GetEtag();
var newTask = new PlannerTask {
ConversationThreadId = "YYYYYYYY"
};
await graphClient.Planner.Tasks[plannerTask.Id]
.Request()
.Header("Prefer", "return=representation")
.Header("If-Match", eTagId)
.UpdateAsync(newTask);
This is because it is not a PUT but a PATCH, and so we only should send the fields that have changed. I was sending the full object, and that was the problem. Now I create newTask and only specify "ConversationThreadId" in it. This way works like a charm for me.
I'm trying to use Tweetinvi to retrieve all the tweets made by a particular screen name.
I've tried GetUserTimeLine (see below) but it shows tweets from all the people I follow instead of just mine.
IUser user = Tweetinvi.User.GetUserFromScreenName("SCREEN_NAME");
// Create a parameter for queries with specific parameters
var timelineParameter = Timeline.CreateUserTimelineRequestParameter(user);
timelineParameter.ExcludeReplies = true;
timelineParameter.TrimUser = true;
timelineParameter.IncludeRTS = false;
var tweets = Timeline.GetUserTimeline(timelineParameter);
return tweets;
Thanks,
Travis
A little late, but maybe useful for others (using the Tweetinvi NuGet 0.9.12.1) :
Tweetinvi.Core.Interfaces.IUser user2 = Tweetinvi.User.GetUserFromScreenName("StackOverflow");
var userTimelineParam = new Tweetinvi.Core.Parameters.UserTimelineParameters
{
MaximumNumberOfTweetsToRetrieve = 100,
IncludeRTS=true
};
List<Tweetinvi.Core.Interfaces.ITweet> tweets2= new List<Tweetinvi.Core.Interfaces.ITweet>();
tweets2 = Timeline.GetUserTimeline(user2, userTimelineParam).ToList();
foreach (Tweetinvi.Core.Interfaces.ITweet prime2 in tweets2)
{
Debug.WriteLine(prime2.CreatedAt+" "+prime2.Text+" "+prime2.Id.ToString());
}
Twitter does not provide such endpoint. Therefore you will need to filter the tweets that have not been created by yourself.
Simply use linq (using System.Linq) to filter down the result after your code:
var tweetsPublishedByMyself = tweets.Where(x => x.Creator.Equals(user)).ToArray();
Using System.DirectoryServices, one can get the highestCommittedUSN this way:
using(DirectoryEntry entry = new DirectoryEntry("LDAP://servername:636/RootDSE"))
{
var usn = entry.Properties["highestCommittedUSN"].Value;
}
However, I need to get this information from a remote ADLDS using System.DirectoryServices.Protocols, which does not leverage ADSI. Following is a simplified code sample of what I'm attempting to do:
using(LdapConnection connection = GetWin32LdapConnection())
{
var filter = "(&(highestCommittedUSN=*))";
var searchRequest = new SearchRequest("RootDSE", filter, SearchScope.Subtree, "highestCommittedUSN");
var response = connection.SendRequest(searchRequest) as SearchResponse;
var usn = response.Entries[0].Attributes["highestCommittedUSN"][0];
}
Unfortunately this kicks back a "DirectoryOperationException: The distinguished name contains invalid syntax." At first I thought there might be something wrong in GetWin32LdapConnection() but that code is called in numerous other places to connect to the directory and never errors out.
Any ideas?
Thanks for the idea, Zilog. Apparently to connect to the RootDSE, you have to specify null for the root container. I also switched the filter to objectClass=* and the search scope to "base." Now it works!
using(LdapConnection connection = GetWin32LdapConnection())
{
var filter = "(&(objectClass=*))";
var searchRequest = new SearchRequest(null, filter, SearchScope.Base, "highestCommittedUSN");
var response = connection.SendRequest(searchRequest) as SearchResponse;
var usn = response.Entries[0].Attributes["highestcommittedusn"][0];
}
I hope this saves someone else some time in the future.
I've been trying to get all the RoleAssignments using the COM interface. the problem is that i get the AD user group names instead of the actual users inside the groups.
my code looks something like this:
ClientContext cc = new ClientContext(#SiteURL);
RoleAssignmentCollection Roles = cc.Web.RoleAssignments;
IEnumerable<RoleAssignment> newRoleAssignmentsCollection = cc.LoadQuery(Role.Include(role => role.Member));
AsyncDelegate execDel = new AsyncDelegate(cc.ExecuteQuery);
execDel.BeginInvoke(arg => { cc.ExecuteQuery();
foreach (RoleAssignment RoleAssign in newRoleAssignmentsCollection)
{
RoleAssign.Member.LoginName; // <------- Here is my problem!!!
}
}, null);
Can anyone please tell me how to get the users which are inside the Active Directory group?
Thanks in advance, Itay.