Automating site collection creation in SharePoint

UPDATE

I can now successfully impersonate the UI. It was a problem with the code I was using and after looking at Jay Nathan's article I put his code back and everything works fine.

In response to a comment, this is the code I am using to create a new site collection:

Dim newSite As SPSite = webApp.Sites.Add( _
    txtWebApp.Text & "/cg/" & strURL, txtName.Text, txtDesc.Text, 1033, "SITEDEF#0", _
    "DOMAIN\ACCOUNT", "NAME", "EMAIL", _
    "DOMAIN\ACCOUNT", "NAME", "EMAIL")

      

and yes "SIDEEF # 0" is an absolutely correct definition of a site.

Hopefully I got around this problem by using the app page, which is available as an item in the Site Actions menu (for site admins only). Using impersonation, I can successfully initiate this process. There are a few additional questions that I have highlighted in another question.

ORIGINAL QUESTION

I need to allow non-farm admins to create site collections using a very specific site definition. These people will not have access to the central administrator and therefore require a special solution to create them. I have tried several solutions, but I want to achieve some consensus on the recommended approach.

  • Custom web service. I wrote my own web service to do this task, however it caused some serious headaches and even though the web service was running in the app pool using the same id as the sharepoint app pool I couldn't get this to work ... Also there were form overflow issues when trying to execute this v ia web service.

  • Web part / application page. There are no form overflow issues here since we are in a SharePoint context, however I tried to use RunWithElevatedPrivileges, but I still got access denied when calling SPWebbApplication.Sites.Add () even though all SPSite and SPWeb objects are created inside the elevated code block. I have tried direct impersonation at the UI level and I get an UnhandledException saying that the impersonation has failed.

  • Application Wrapper Around stsadm - I haven't tried this yet as I'm worried about the viability of this approach, of course there is a cleaner way than this?

Some guidance on this will be helpful as I can't find much in there.

thank

+2


source to share


2 answers


I would go with option number 1. This is probably an authorization issue. How do you access SharePoint? from the SDK or through its web services?



0


source


I would go for number 2. This code should work, maybe the impersonation code is wrong? You cannot use SPContext as you normally would, eg.



Additionally, you enhance the identity of your SharePoint site's application pool. Does this account have sufficient rights to create site collections? You can check Administration Management> Application Management> Policy for Web Application.

0


source







All Articles