Paul Galvin's (old) SharePoint space [SharePoint

Just another WordPress.com site

Quick and Simple: Provision a Web Site Using SharePoint Object Model In C#

I tried searching for a little snippet code that would show how I can create a new SPWeb in a site collection.  I didn’t find it as quickly or easily as I expected so I thought I’d slap together a little entry on the subject.

This code creates a new Wiki site:

    SPSite siteCollection;

    siteCollection = new SPSite("http://conchang-o9l8qi");

    SPWeb w = siteCollection.OpenWeb();

    w.Webs.Add("xyzzy", "xyzzy Title",
        "xyzzy description", 1033, SPWebTemplate.WebTemplateWIKI, false, false);

My initial searches failed because I was looking for phrases like "provision a web site using sharepoint object model" and the like. 

If you search for "Webs.Add()", you’ll find a number of very useful blog entries, MSDN articles and SDK documentation that go into depth on this subject.  I definitely recommend this site.

</end>

 Subscribe to my blog.

Technorati Tags:
Advertisements

3 responses to “Quick and Simple: Provision a Web Site Using SharePoint Object Model In C#

  1. Unknown March 12, 2008 at 4:12 am

    WSS SDK contains plenty of examples. Thinking in the terms of SharePoint object model really helps I have found out. As Sites are stored under a Site Collection you would look for a property of SPSite which contains the sites (SPSite.AllWebs). As this property is a collection of type SPWebCollection you would go there and found out the various versions of the Add method including the code snippet.

  2. Tobias March 12, 2008 at 8:32 am

    Hi,
     
    Don\’t forget about disposing the objects after you\’re done with them. Tends to get quite a resource hog if one has many custom application where one doesn\’t take the disposal of objects into consideration, especially if there\’s a lot of concurrent users.
     
    This MSDN article describes the disposal of objects rather well, and takes up some examples of where the resources tend to run low if you forget about disposals 🙂
    http://msdn2.microsoft.com/en-us/library/bb687949.aspx?s=21
     
    I usually do like;
     
    using(SPSite someSite = new SPSite(http://litware.inc/)){
       //Do stuff here
    }
     

  3. Rebecca March 12, 2008 at 9:39 am

    I did this last year.  I will say it was a lot easier to find resources last year.  This year with more devs blogging it\’s getting to be an information bog down.  It has it\’s good and bad qualities.  We have more about stuff we didn\’t know about last year, but we also have way too much on the same thing sometimes.  There is a book by Todd Bleeker:

    Developer\’s Guide to the Windows SharePoint Services v3 Platform
    It has some stuff about provisioning and hitting the object model a bit.  I would say it\’s one of the best books with information about the Object Model.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: