View Single Post
  #1 (permalink)  
Old June 17th, 2008, 05:11 AM
millerthegorilla millerthegorilla is offline
Registered User
Join Date: Jun 2008
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to add a site programatically

In sharepoint you can add a site below the current site by clicking on site actions > create > sites and workspaces. I'd like to that programatically in a webpart. What I've done so far is to get the current site (SPSite currentSite = new SPSite(currentUrl);) and then get the webapplication object (SPWebApplication spwa = currentSite.WebApplication;) I then call spwa.sites.add with the appropriate parameters. However, sharepoint throws an exception that the site already exists if I give it the url of the current site plus the new site url. For instance, if the current sites url is 'http://server/personal/admin' and I want to create a site with the url of '/subsite' I've been trying to call spwa.sites.add with the url parameter set to 'http://server/personal/admin/subsite'. This is when sharepoint complains. The only way I've been able to create a site is to pass in 'sites/subsite' as the url parameter of spwa.sites.add. How do I create a site as a subsite of the current site then?
Reply With Quote