Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SharePoint > SharePoint Development
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
SharePoint Development Programming and development for SharePoint Portal Server and Windows SharePoint Services
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SharePoint Development section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 17th, 2008, 05:11 AM
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
  #2 (permalink)  
Old June 17th, 2008, 11:43 AM
Registered User
 
Join Date: Jun 2008
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Somebody answered this question on another forum. It works like this:
            SPSite currentSite = new SPSite(currentUrl);
            SPWeb currentWeb = currentSite.OpenWeb();
            SPUser currentUser = currentWeb.CurrentUser;

            currentWeb.AllowUnsafeUpdates = true;
            currentWeb.Update();
            SPWebCollection subsites = currentWeb.Webs;

            string url = newUrlText.Text;

           try
           {
               subsites.Add(url,
                            newSiteTitleText.Text,
                            siteDescriptionText.Text,
                            (uint)(1033),
                            siteTemplateList.SelectedItem.Value,
                            true,
                            false);
....
           finally
           {
               currentWeb.AllowUnsafeUpdates = false;
               currentWeb.Update();
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to add task in Scheduled Task programatically amitjoshipune C# 2 July 31st, 2008 05:42 AM
MaxDataAxisValue programatically ganans Crystal Reports 0 May 6th, 2006 06:30 PM
how to add breadcrumb navigation to a LAMP site avail1now PHP How-To 0 February 17th, 2006 05:03 PM
Using data programatically jasongorringe ASP.NET 2.0 Basics 1 February 10th, 2006 02:42 PM
how do i change the site icon on a geocitiies site uprocker2 HTML Code Clinic 2 March 4th, 2005 07:20 AM



All times are GMT -4. The time now is 11:53 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.