I got following error message when I try to create folder/item in my web service, may I ask your advise?
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)
The web service (both application pool and pass through authentication) using local administrator account which also a site collection administrator
My Server Information as below: - Windows Server 2012 - SharePoint 2013 - SQL Server 2012
Web Service .NET Version (4.0)
Web Service Code (for test):
With delegate (and still not works if comment out "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";
}
Thank you very much for your attention.