locked
Create Site Collection Programatically from Top level Site Collections RRS feed

  • Question

  • Hi,

    How to create different Site Collection Programmatically as a Visual Web Part in Top Level Site Collection in same web Application.


    Ravindranath

    Sunday, September 13, 2015 10:26 AM

Answers

  • Hi,

    According to your description, my understanding is that you want to create different site collection in the same web application using web part in top level site collection.

    I suggest you can create a custom web part and with the code snippet like below to create site collection for the specific web application:

    string SiteCollectionUrl = "/sites/test3";
    
                Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(() =>
                {
                    var Application = SPWebApplication.Lookup(new Uri("http://sp2013sps/"));
                    Application.Sites.Add(SiteCollectionUrl, "TeamSite Created By C#", string.Empty, 1033, "STS#0", "contoso\\Administrator", "contoso\\Administrator", String.Empty);
                });

    Thanks

    Best Regards


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    Monday, September 14, 2015 6:43 AM

All replies

  • Ravi,

    You can run PowerShell script for creating site collection in webpart.

    I haven't tried myself but below link can help you to 

    Take a look at http://www.codeproject.com/KB/cs/HowToRunPowerShell.aspx. This is the type of code you'll need to write/consider.

    Sunday, September 13, 2015 11:17 AM
  • Hi,

    According to your description, my understanding is that you want to create different site collection in the same web application using web part in top level site collection.

    I suggest you can create a custom web part and with the code snippet like below to create site collection for the specific web application:

    string SiteCollectionUrl = "/sites/test3";
    
                Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(() =>
                {
                    var Application = SPWebApplication.Lookup(new Uri("http://sp2013sps/"));
                    Application.Sites.Add(SiteCollectionUrl, "TeamSite Created By C#", string.Empty, 1033, "STS#0", "contoso\\Administrator", "contoso\\Administrator", String.Empty);
                });

    Thanks

    Best Regards


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    Monday, September 14, 2015 6:43 AM