首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 企业软件 > 行业软件 >

请问sharepoint 2007 SDK createUser方法的用法(C#)

2013-01-28 
请教sharepoint 2007 SDK createUser方法的用法(C#)小弟不才,弄了很久都不知道C#中怎样去使用该方法,我是

请教sharepoint 2007 SDK createUser方法的用法(C#)
小弟不才,弄了很久都不知道C#中怎样去使用该方法,我是想自己写一个C#程序,然后通过SDK提供的CreateUser方法创建sharepoint用户,希望高手们可以帮忙写个例子。谢谢···
[解决办法]

 SPSecurity.RunWithElevatedPrivileges(delegate()
    {
        using (SPSite site = new SPSite("http://localhost:partnumber/siteUrl"))
        {
            using (SPWeb web = site.OpenWeb())
            {
                bool allowUnsafeUpdate = web.AllowUnsafeUpdates;
                web.AllowUnsafeUpdates = true;
                
//User Entity
                string loginName = "Domain\UserName";
string userName = "UserName";
                string email = "UserEmail@Mail.com"
                string notes = "Automatically added user";
                
//Group
                string groupName = "Viewers";
                SPGroup addUserGroup = web.Groups["Viewers"];
                addUserGroup.AddUser(loginName, email, userName, notes);

                web.AllowUnsafeUpdates = allowUnsafeUpdate;
            }
        }
    });

[解决办法]
没太看懂CreateUser这个方法是指什么,494175469 加我吧,可以讨论一下。奉上一段codeplex上找到例子,希望对你有帮助

private SPUser CreateUser(string strLoginName, string strEMail, 
    string strName, string strNotes, string strSiteURL)
{
    SPUser spReturn = null;
    SPSite spSite = null;
    SPWeb spWeb = null;

    try
    {
        //Open the SharePoint site
        spSite     = new SPSite(strSiteURL);
        spWeb     = spSite.OpenWeb();

        //Assign role and add user to site
        SPRoleAssignment spRoleAssignment = 
            new SPRoleAssignment(strLoginName, strEMail, strName, strNotes);


        //Using Contribute, might need high access
        SPRoleDefinition spSPRoleDefinition = 
            spWeb.RoleDefinitions["Contribute"]; 
    
        spRoleAssignment.RoleDefinitionBindings.Add(spSPRoleDefinition);
        spWeb.RoleAssignments.Add(spRoleAssignment);

        //Update site
        spWeb.Update();
        spReturn = spWeb.AllUsers[strLoginName];
    }
    catch(Exception)
    { 
    }
    finally
    {
        spWeb.Close();
        spSite.Close();
    }

    return spReturn;
}
[解决办法]
大家好像对sharepoint的用户机制不是太了解吧?sharepoint里的用户都是域中的用户,是没办法在sharepoint中直接创建用户的,上边各位提供的不是创建用户,而是对域中的用户授权!!
[解决办法]
如果是系统添加AD用户,建议使用User Profile来同步AD用户到SharePoint中来。

热点排行