C# SharePoint 2013-System.UnauthorizedAccessException:访问被拒绝
当我尝试在我的web服务中创建文件夹/项目时,我收到了以下错误消息,请问您有何建议C# SharePoint 2013-System.UnauthorizedAccessException:访问被拒绝,c#,sharepoint,sharepoint-2013,access-denied,C#,Sharepoint,Sharepoint 2013,Access Denied,当我尝试在我的web服务中创建文件夹/项目时,我收到了以下错误消息,请问您有何建议 System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)) at Microsoft.SharePoint.Utilities.SPUtility.HandleAccessDenied(Exception ex) at Microsoft.Shar
System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
at Microsoft.SharePoint.Utilities.SPUtility.HandleAccessDenied(Exception ex)
at Microsoft.SharePoint.Library.SPRequest.AddOrUpdateItem …… (SKIP)
使用本地管理员帐户的web服务(应用程序池和直通身份验证),该帐户也是网站集管理员
我的服务器信息如下:
-Windows Server 2012
-SharePoint 2013
-SQL Server 2012
Web服务.NET版本(4.0)
Web服务代码(用于测试):
使用委托(如果注释掉“RunWithElevatedPrivileges”,则仍然不起作用):
非常感谢您的关注。本期与SP 2013和web服务有关。同样的代码也适用于SP 2010。要解决此问题,请使用Win32 API模拟。请查看此帖子的答案-
public string TestCreateFolderTestingElevatedSecurity()
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite oSPsite = new SPSite(strSharePointSite))//http://localhost
{
oSPsite.AllowUnsafeUpdates = true;
using (SPWeb oSPWeb = oSPsite.OpenWeb())
{
oSPWeb.AllowUnsafeUpdates = true;
/* Path within the list where the new folder gets created
Leave it empty if it needs to be created under root */
String nodeDepthPath = @"";
/* get the list instance by name */
SPList list = oSPWeb.Lists.TryGetList(strTestDocLib);//DocumentLibrary
/* create a folder under the path specified */
SPListItem folderItem = list.Items.Add(
list.RootFolder.ServerRelativeUrl + nodeDepthPath,
SPFileSystemObjectType.Folder, strNewFolderName);//FolderName
/* set the folder name and update */
folderItem.Update();
oSPWeb.AllowUnsafeUpdates = false;
}
oSPsite.AllowUnsafeUpdates = false;
}
});
return "Success";
}