SharePoint user tasks
You can use the SharePoint .NET Framework CSOM to manage SharePoint users, groups, and user security.
Add a user to a SharePoint group
This example adds a user and some user information to a SharePoint group named Members.
// Starting with ClientContext, the constructor requires a URL to the
// server running SharePoint.
ClientContext context = new ClientContext("http://SiteUrl");
GroupCollection siteGroups = context.Web.SiteGroups;
// Assume that there is a "Members" group, and the ID=5.
Group membersGroup = siteGroups.GetById(5);
// Let's set up the new user info.
UserCreationInformation userCreationInfo = new UserCreationInformation();
userCreationInfo.Email = "user@domain.com";
userCreationInfo.LoginName = "domain\\user";
userCreationInfo.Title = "Mr User";
// Let's add the user to the group.
User newUser = membersGroup.Users.Add(userCreationInfo);
context.ExecuteQuery();
Retrieve all users in a SharePoint group
This example retrieves information about all users from a SharePoint group named Members.
// Starting with ClientContext, the constructor requires a URL to the
// server running SharePoint.
ClientContext context = new ClientContext("http://SiteUrl");
GroupCollection siteGroups = context.Web.SiteGroups;
// Assume that there is a "Members" group, and the ID=5.
Group membersGroup = siteGroups.GetById(5);
context.Load(membersGroup.Users);
context.ExecuteQuery();
foreach (User member in membersGroup.Users)
{
// We have all the user info. For example, Title.
label1.Text = label1.Text + ", " + member.Title;
}
Create a role
This example creates a role that has create and manage alerts permissions.
// Starting with ClientContext, the constructor requires a URL to the
// server running SharePoint.
ClientContext context = new ClientContext("http://SiteUrl");
BasePermissions perm = new BasePermissions();
perm.Set(PermissionKind.CreateAlerts);
perm.Set(PermissionKind.ManageAlerts);
RoleDefinitionCreationInformation creationInfo = new RoleDefinitionCreationInformation();
creationInfo.BasePermissions = perm;
creationInfo.Description = "A role with create and manage alerts permission";
creationInfo.Name = "Alert Manager Role";
creationInfo.Order = 0;
RoleDefinition rd = context.Web.RoleDefinitions.Add(creationInfo);
context.ExecuteQuery();
Add a user to a role
This example adds a user to a role.
// Starting with ClientContext, the constructor requires a URL to the
// server running SharePoint.
ClientContext context = new ClientContext("http://SiteUrl");
// Assume that we have a SiteUser with Login user.
Principal user = context.Web.SiteUsers.GetByLoginName(@"domain\user");
// Assume that we have a RoleDefinition named "Read".
RoleDefinition readDef = context.Web.RoleDefinitions.GetByName("Read"); RoleDefinitionBindingCollection roleDefCollection = new RoleDefinitionBindingCollection(context);
roleDefCollection.Add(readDef);
RoleAssignment newRoleAssignment = context.Web.RoleAssignments.Add(user, roleDefCollection); context.ExecuteQuery();
You really make it seem so easy with your presentation but I find
this topic to be actually something which I think I would never understand.
It seems too complex and very broad for me. I am looking forward for
your next post, I’ll try to get the hang of it!
sure , no problem .. but please mention my website as a source
It is really a nice and useful piece of info. I’m satisfied that you shared this helpful information with us.
Please stay us up to date like this.
I’m extremely pleased to uncover this web site.
I want to to thank you for ones time for this particularly
wonderful read!! I definitely savored every bit of it and I have you
saved as a favorite to look at new stuff in your blog.
I have read so many articles or reviews regarding the blogger lovers but this paragraph is really a good article, keep it up.
I love it when folks get together and share ideas. Great site, continue the good work!
Someone essentially lend a hand to make severely posts I would
state. That is the very first time I frequented your web page
and up to now? I amazed with the analysis you made to make this actual post incredible.
Magnificent job!
It is appropriate time to make some plans for the future and it’s time to be happy.
I’ve read this post and if I could I want to suggest you few interesting things or tips.
Maybe you could write next articles referring to this article.
I desire to read even more things about it!
I every time emailed this blog post page to all my associates, since
if like to read it after that my friends will too.
My developer is trying to persuade me to move to .net
from PHP. I have always disliked the idea because of the
expenses. But he’s tryiong none the less. I’ve been using WordPress on a variety of websites for
about a year and am nervous about switching to another platform.
I have heard very good things about blogengine.net.
Is there a way I can transfer all my wordpress posts into
it? Any help would be really appreciated!
Fantastic beat ! I would like to apprentice while you amend your site, how can i subscribe for a blog site?
The account aided me a acceptable deal. I had been a little bit acquainted of this your broadcast offered
bright clear idea
My brother recommended I might like this blog.
He was totally right. This post truly made my day.
You cann’t imagine just how much time I had spent for this information! Thanks!
Pretty nice post. I just stumbled upon your blog and wanted to say that I have truly enjoyed browsing your blog posts.
In any case I will be subscribing to your rss feed
and I hope you write again very soon!
Excellent beat ! I wish to apprentice while you amend your web site, how can i subscribe for
a blog website? The account aided me a acceptable deal. I had been a
little bit acquainted of this your broadcast
offered bright clear idea
Everything is very open with a really clear clarification of the challenges.
It was really informative. Your site is useful. Thank you for sharing!
Hello! Would you mind if I share your blog with my zynga group?
There’s a lot of people that I think would really enjoy your content.
Please let me know. Thank you
hello dear
sure you can share it any time anywhere but please mention my website at the end of your post
Hey there! I’m at work browsing your blog from my new iphone
4! Just wanted to say I love reading your blog and look forward to all
your posts! Carry on the excellent work!
I read this paragraph fully on the topic of
the comparison of most recent and previous technologies,
it’s amazing article.
Yes! Finally someone writes about desatrancos.
Hi! I just wish to offer you a huge thumbs up for your great info you’ve got right here on this post.
I will be returning to your website for more soon.
Hello! Someone in my Myspace group shared this website with us so I came to give it a look.
I’m definitely loving the information. I’m bookmarking and will be tweeting this to my
followers! Superb blog and brilliant style and design.
Thanks in favor of sharing such a nice thinking, article is
pleasant, thats why i have read it entirely
Great goods from you, man. I’ve bear in mind your
stuff previous to and you’re just too great. I actually like what you have obtained here, certainly like
what you’re stating and the best way through which you
are saying it. You make it enjoyable and you
still take care of to stay it sensible. I can’t wait to learn much more from you.
That is actually a great web site.
Fantastic post however I was wanting to know if you could write a litte more on this topic?
I’d be very thankful if you could elaborate a little
bit further. Thanks!
whoah this blog is fantastic i love reading your posts.
Keep up the great work! You know, lots of persons
are searching round for this info, you can help them greatly.
I’d have to examine with you here. Which is not one thing I usually do! I take pleasure in reading a post that may make folks think. Additionally, thanks for permitting me to comment!
Good day! This is my first comment here so I just wanted to give
a quick shout out and say I truly enjoy
reading through your articles. Can you suggest any other blogs/websites/forums that go over the
same topics? Many thanks!
What’s up everyone, it’s my first go to see
at this website, and paragraph is genuinely fruitful
for me, keep up posting these content.
Very good post. I will be dealing with many of these issues as well..