locked
Access is denied when create sub site programmatically RRS feed

  • Question

  • Hi all,

     

    I encounter a problem to create a sub site programmatically.

     

    In our sharepoint application, we have a list event handler to create a site when there is a new record is created in the list. The event handler then will use a custom site template to create the new site.

     

    There is no problem when a site collection administrator to create a sub site using the functionality above. But when a user who is in a custom group (group permission level is listed below) trying to create a sub site. We caught the exception below.

     

       Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

     

       at Microsoft.SharePoint.SPGlobal.HandleUnauthorizedAccessException(UnauthorizedAccessException ex)

       at Microsoft.SharePoint.Library.SPRequest.AccessContentTypes(String bstrUrl, Boolean bUpdate)

       at Microsoft.SharePoint.SPContentType.CopyResourcesToCore(SPContentType ct, Boolean ignoreSealedOrReadOnly, Boolean throwOnSealedOrReadOnly)

       at Microsoft.SharePoint.SPContentType.CopyResourcesTo(SPContentType ct)

       at Microsoft.SharePoint.SPContentType.Sync(SPContentType ct)

       at Microsoft.SharePoint.SPContentType.SyncNewList(SPList list)

       at Microsoft.SharePoint.SPWeb.SyncNewLists()

       at Microsoft.SharePoint.SPWeb.ApplyWebTemplate(String strWebTemplate)

       at Microsoft.SharePoint.SPWeb.CreateWeb(String strWebUrl, String strTitle, String strDescription, UInt32 nLCID, String strWebTemplate, Boolean bCreateUniqueSubweb, Boolean bConvertIfThere)

       at Microsoft.SharePoint.SPWeb.SPWebCollectionProvider.CreateWeb(String strWebUrl, String strTitle, String strDescription, UInt32 nLCID, String strWebTemplate, Boolean bCreateUniqueSubweb, Boolean bConvertIfThere)

       at Microsoft.SharePoint.SPWebCollection.Add(String strWebUrl, String strTitle, String strDescription, UInt32 nLCID, String strWebTemplate, Boolean useUniquePermissions, Boolean bConvertIfThere)

       at Microsoft.SharePoint.SPWebCollection.Add(String strWebUrl, String strTitle, String strDescription, UInt32 nLCID, SPWebTemplate WebTemplate, Boolean useUniquePermissions, Boolean bConvertIfThere)

       at CustomSiteCreator.CreateWebSite(String parentURL, String siteTitle, String siteDescription, String projectType)

       at CustomListEventReceiver.ItemAdded(SPItemEventProperties properties)

     

     

    Does anyone have any idea with this error? I am wondering if it is because the user doesn’t have access to the Site Template List.

     

    Permission Level

    All list permission

    Site Permission:

    • Create Subsites  -  Create subsites such as team sites, Meeting Workspace sites, and Document Workspace sites.
    • Manage Web Site  -  Grants the ability to perform all administration tasks for the Web site as well as manage content.
    • Add and Customize Pages  -  Add, change, or delete HTML pages or Web Part Pages, and edit the Web site using a Windows SharePoint Services-compatible editor.
    • Browse Directories  -  Enumerate files and folders in a Web site using SharePoint Designer and Web DAV interfaces.

    • View Pages  -  View pages in a Web site.

    • Enumerate Permissions  -  Enumerate permissions on the Web site, list, folder, document, or list item

    • Browse User Information  -  View information about users of the Web site

    • Use Remote Interfaces  -  Use SOAP, Web DAV, or SharePoint Designer interfaces to access the Web site

    • Use Client Integration Features  -  Use features which launch client applications. Without this permission, users will have to work on documents locally and upload their changes

    • Open  -  Allows users to open a Web site, list, or folder in order to access items inside that container

    Thanks in advance.

    Chris

    Wednesday, October 17, 2007 10:06 PM

Answers

  •  

    After doing search on this forum (maybe a bit late), I found the solution. I should sround my code to create new sub site in the RunWithElevatedPrivileges.

    e.g.

     

    SPSecurity.RunWithElevatedPrivileges(delegate()

    {

    //code to create your site here...

    });

    Thursday, October 18, 2007 1:30 AM