SharePoint 2013 - System.UnauthorizedAccessException: Access is denied

2

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.

c#
sharepoint
sharepoint-2013
access-denied
asked on Stack Overflow May 10, 2014 by user3623376

1 Answer

0

This issue is with SP 2013 & web services. Same code will work fine with SP 2010. To fix this issue use Win32 API impersonation. Check out the answer from this post - http://social.msdn.microsoft.com/Forums/sharepoint/en-US/6c306583-5d90-49e7-a213-c0410b705b27/impersonation-not-working-in-sharepoint-web-service

answered on Stack Overflow Jul 18, 2014 by Hemant Mane

User contributions licensed under CC BY-SA 3.0