我正在尝试以编程方式在项目事件接收器中的另一个Web应用程序中的文档库中创建一个文件夹。以下是我正在使用的代码:
public override void ItemAdded(SPItemEventProperties properties)
{
SPWeb web = properties.Web;
Guid currListID = properties.ListId;
int currListItemID = properties.ListItemId;
try
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(web.Site.ID))
{
using (SPWeb elevWeb = site.OpenWeb(web.ID))
{
site.AllowUnsafeUpdates = true;
elevWeb.AllowUnsafeUpdates = true;
SPList elevList = elevWeb.Lists[currListID];
SPListItem elevCurrItem = elevList.GetItemById(currListItemID);
createProjectFolder(elevCurrItem.Title);
elevWeb.AllowUnsafeUpdates = false;
site.AllowUnsafeUpdates = false;
}
}
});
}
catch (Exception ex)
{
}
base.ItemAdded(properties);
}
private void createProjectFolder(string projectTitle)
{
try
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite spSite = new SPSite(SPSiteUrl))
{
spSite.AllowUnsafeUpdates = true;
using (SPWeb spWeb = spSite.OpenWeb())
{
spWeb.AllowUnsafeUpdates = true;
SPList spList = spWeb.Lists[destListName];
SPListItem newFolder = spList.Items.Add("", SPFileSystemObjectType.Folder, projectTitle);
newFolder.Update();
spWeb.AllowUnsafeUpdates = false;
}
spSite.AllowUnsafeUpdates = false;
}
});
}
catch (Exception ex)
{
}
}
但是我收到以下错误:
{“访问被拒绝。(HRESULT异常:0x80070005(E_ACCESSDENIED))”}
at Microsoft.SharePoint.SPGlobal.HandleUnauthorizedAccessException(UnauthorizedAccessException ex) 在Microsoft.SharePoint.Library.SPRequest.GetListsWithCallback(字符串bstrUrl,的Guid foreignWebId,字符串bstrListInternalName,的Int32 dwBaseType,的Int32 dwBaseTypeAlt,的Int32 dwServerTemplate,UInt32的dwGetListFlags,UInt32的dwListFilterFlags,布尔bPrefetchMetaData,布尔bSecurityTrimmed,布尔bGetSecurityData,布尔bPrefetchRelatedFields,ISP2DSafeArrayWriter p2DWriter, Int32& plRecycleBinCount) 在Microsoft.SharePoint.SPListCollection.EnsureListsData(Guid webId,String strListName) at Microsoft.SharePoint.SPListCollection.GetListByName(String strListName,Boolean bThrowException) 在ER_EPMProjectCenterList.ER_ProjectCenterItemAdded.ER_ProjectCenterItemAdded。<> c__DisplayClass6.b__4() 在Microsoft.SharePoint.SPSecurity。<> c__DisplayClass5.b__3() 在Microsoft.SharePoint.Utilities.SecurityContext.RunAsProcess(CodeToRunElevated secureCode)
我知道我收到此错误是因为我正在尝试访问列表跨域。是否有任何工作来实现这一目标。我需要你的帮助。