问题描述
我们有一个SharePoint 2010应用程序,可以在AD中以编程方式创建用户个人资料, 然后使用AD中的数据进一步创建Sharepoint 2010配置文件。 有时我们会收到以下错误:
感谢您的帮助。
错误: System.ComponentModel.Win32Exception:在Microsoft.Office.Server.Utilities.Win32.AdvApi.LookupAccountName(String lpSystemName,String lpAccountName,IntPtr Sid,Int32&cbSid,StringBuilder ReferencedDomainName,Int32&cchReferencedDomainName,Int32&cchReferencedDomainName, peUse)_
代码:
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(strSiteUrl))
{
site.AllowUnsafeUpdates = true;
UserProfile user = null;
HttpContext oldContext = HttpContext.Current;
SPServiceContext context = SPServiceContext.GetContext(site);
HttpContext.Current = null;
UserProfileManager currentUserProfileManager = new UserProfileManager(context);
bool userexist = false;
try
{
user = currentUserProfileManager.GetUserProfile(accountName);
userexist = true;
}
catch (Exception ex)
{
userexist = false;
}
if (currentUserProfileManager != null)
{
if (!userexist)
{
try
{
user = currentUserProfileManager.createuserProfile(accountName);
}
catch (Exception ex)
{
throw;
}
}
}
}
}
解决方法
我认为使用共享点工具创建用户是不可能的。您首先需要使用以下方法在AD中创建一个帐户: https://www.codeproject.com/Articles/90142/Everything-in-Active-Directory-via-C-NET-Using
然后才在共享点中设置配置文件的复制