Partager via


SharePoint : Add group of users to the user collection programmatically

The sample code as follows.

    SPWeb web = new SPSite("Site URL").OpenWeb();
    SPUserInfo[] userInfo = new SPUserInfo[1];
    userInfo[0].Email = "email@microsoft.com";
    userInfo[0].LoginName = @"domain\username";
    userInfo[0].Name = "username";
    userInfo[0].Notes = "Test";
    web.Roles["Reader"].Users.AddCollection(userInfo);

Comments

  • Anonymous
    May 25, 2007
    Hello, I've made an outlook sharepoint integration on 1 machine. A BIG application. An Outlook Add-in project. Huge, and now I tried it on a clientmachine and I get the error when using theSite = SPSite(clsUtils.siteName) about not finding the file Microsoft.Sharepoint.intl. That file is not on my client computer. Don't tell me we can't use the SPSite en Web objects on client machines. What is the solution here?

  • Anonymous
    October 23, 2007
    Hi Karthick Not sure if you still update this blog but i'm kinda desperate for some more info on this I'm trying to add a user to a group but it keeps asking for a SharePoint administrator login when i try and add.  my SPWeb object has the correct profiles and when i spell the role incorrectly it gives me an error.   It's just the AddUserToGroup function that is giving me the headache :¬( any Ideas please? cheers Tim At Slashwoot dot Com

  • Anonymous
    October 03, 2011
    <a href="j2me-aspnet.blogspot.com/">Very helpful for me</a>