I got the task to create a custom web part for sharepoint server 2010 where a user enters details about a site. Fields are: title, description, dropdown with a list of site templates, listboxes with user groups and listboxes with site permissions (full access/contribute/read only). An administrator is supposed to be able to select one/many groups in one listbox and populate the permission listbox with these groups.

The webpart will then create a site with the specified template and the specified permissions. Is all this possible to achieve with a custom web part? I have worked with the provided SharePoint web services before (mostly Lists.asmx though) so I know how to use some of them. I know there is an Admin service but does it provide me with enough permission/parameters to set all these things?

This is my first custom web part and I have started to create a SharePoint 2010 Visual Web part in VS2010 and before I dig too much deeper I'd like to hear some opinions.

Thanks in advance.

3 Answers 3


To my knowledge there is not an out of the box SharePoint 2010 web service that will you can call to create a new site. You would need to use the SharePoint object model to do this instead. I have not been able to validate this code as I'm not on my work machine right now, but I think this code will give you a basic idea of how to create a new site (SPWeb) within an existing SiteCollection:

protected void CreateSite(string siteUrl, string newSiteName, SPFieldUserValue siteOwner)
    using (SPSite siteCollection = new SPSite(“http://SPSite”))
      using (SPWeb web = siteCollection.OpenWeb())
        web.AllowUnsafeUpdates = true;

        // Set the user for your new site
        string ownerLogin = siteOwner.User.LoginName; //user’s login name
        string ownerEmail = siteOwner.User.Email;
        string ownerName = siteOwner.User.Name;

        //Create new web site
        SPWeb newWeb = siteCollection.Add(“/” + siteUrl, newSiteName, “site description”, 1033,{Name of the Site Template}, ownerLogin,ownerName,ownerEmail );

Since you're trying to use a web part to execute this code you may need to surround the portion of code that is creating the site with SPSecurity.RunWithElevatedPrivileges.

  • Hi Robert, thanks for your input, I am trying out the code and under //Create new web site I try to do siteCollection.Add but there's no Add only AddWorkItem?
    – Peter
    Dec 13, 2010 at 4:25
  • While I did not succeed in creating a new site with the code above you did manage to put me in the right direction of using the SharePoint object model instead of the web services. I found an example here mylifeinaminute.com/2008/08/07/… and it works.
    – Peter
    Dec 13, 2010 at 4:42

You can create a site collection using the following admin service - " http://Virtual_Server_Name:Port_Number/_vti_adm/Admin.asmx.". The account that accesses this web service must be a member of the Farm Administrators group in the Central Administration site.

More details on the web service is present in the following URL - "http://msdn.microsoft.com/en-us/library/administration.admin.createsite(v=office.12).aspx"

Do you really need to create the site from web part and that too using a web service? I had created solution on the following lines:

  1. InfoPath form to capture new site creation request. (you can also use a webpart instead)
  2. Store the request in the custom list
  3. Timer job to create site (uses object model to create the site collection)

Is it possible to create a new Site collection by calling a built-in SharePoint Web Service?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.