小弟不才,弄了很久都不知道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 = "[email protected]"
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);