请教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;
}
}
});
//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中来。