我得到了以下错误消息时,我尝试在我的Web服务创建文件夹/项,请问您的意见?
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”):
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";
}
非常感谢您的关注。
这个问题是与SP 2013&网络服务。相同的代码将正常工作与2010年SP要解决此问题,使用Win32 API的模拟。从这个帖子退房的答案 - http://social.msdn.microsoft.com/Forums/sharepoint/en-US/6c306583-5d90-49e7-a213-c0410b705b27/impersonation-not-working-in-sharepoint-web-service