Skip to main content

Site provisioning in SharePoint 2007

This article will help you to create your own custom site provisioning that integrates your business process and will show you how to add some custom functionalities.

 

One of the great things about SharePoint is how easy it is to create a new site. The user selects a template he wants, provides a title, description, and URL name for the site… and voila, a new site is born! This out-of-the box functionality allows users, a quick and easy way to create a new site. This is good and easy, but more likely it does not meet with your customer requirements. Particularly in large organizations, when you need to implement a business process or you want to enforce some functionality to save time in support and training.
This article will help you to create your own custom site provisioning that integrates your business process and will show you how to add some custom functionalities.
Below is a diagram showing the entire process and all of the various components and steps that make up the entire process.


After gathering the requirements you need to be able to answer these questions:
  1. What type of site do you need, a site collection or a sub site?
  2. Sites are meant for collaboration or for publishing?
  3. Is approval process needed?
  4. How does the navigation will look like?
  5. Where will your sites be created?
    a. A new sub site under the root site collection e.g. http://server/teamsite/project1
    b. A new site collection at the root level of your Web Application paths e.g. http://server/project1
    c. A new site collection under managed paths e.g. http://server/projects/project1
    d. A new site collection under a different Web Application e.g. http://server-projects/project1 Search
  6. Search – one of the most important part, how users will find the sites?
These questions are important to help you define your provision process.
The Request Form – Keep it simple
The request form should be a simple - easy to use form. When a user wants to create a new site, he needs to fill out some fields, like site title, description, keywords and most important the right template. The site provision process will be based on the chosen template.

Creating the Request Form
As a SharePoint developer, you have a wide variety of methods and techniques to build your request form. You can choose:
  • InfoPath form
  • Web Part
  • A SharePoint List entry
  • ASPX page
  • Web Control
Personally I will recommend building a Web Control and adding this control to a custom aspx page in your application pages (_layouts folder). The advantage of application page, is that exposed in any site collection or sub site, for example, http://server/_layouts/CreateSite.aspx, and unlike content pages, cannot be edited by users.
Site Request List
The second component that your site provision will use is a SharePoint List. This list will help the site administrator to monitor all site requests, and also will give you the possibility to associate custom or out of the box workflows to approve new site requests. Note: If you choose not to associate the request with workflow, Add a SPLongOperation object, because your creation process will takes a while.
using (SPLongOperation longOperation = new SPLongOperation(this.Page))
{
   longOperation.Begin();
   SPWeb newSite = CreateSite(); //this function will start your site provison hendler
   longOperation.End(newSite.Url);
}
 


New SharePoint Site
When you create a new SharePoint site there are two options:
   1. A new Site Collection - use the Add method of the SPWebCollection class.
   2. A new Sub Site - use the Add method of the Webs collection of the SPWeb class.

The following examples create a new Site Collection and a new Sub Site that is based on information gathered from the request form and stored in the Site Request List.
Create Sub Site
private string CreateSubSite(SPListItem item)
{
   SPWeb newWeb = null;
   string url = string.Empty;
   try
   {
      SPSecurity.RunWithElevatedPrivileges(delegate() 
     {
         using (SPSite site = new SPSite(form.HostUrl))
       {
          site.AllowUnsafeUpdates = true;
          using (SPWeb web = site.OpenWeb ())
         {
               string relativeUrl = item["ID"].ToString().PadLeft(6, '0');
             web.AllowUnsafeUpdates = true;
            newWeb = web.Webs.Add(relativeUrl,
               item["Title"].ToString(),
               item["Description"].ToString(),
              1033,
               item["Template"].ToString(),
               true, false);
           url = newWeb.Url;
          newWeb.Dispose();
         }
       }
    });
}
catch (Exception ex)
{
// handle exception
} finally
{
     if (newWeb == null)
        {
         newWeb.Dispose();
        }
      } return url;
}
Create Site Collection
private static string CreateSiteCollection(SPListItem item)
{
  SPSite site = null;
  SPWeb newWeb = null;
  string url = string.Empty;
  try {
     SPSecurity.RunWithElevatedPrivileges(delegate()
       {
         SPWebApplication webApplication = null;
         webApplication = SPWebApplication.Lookup(new Uri (YourHostUrl));
         string relativeUrl = "";
         relativeUrl = item["ID"].ToString().PadLeft(6, '0');
         site = webApplication.Sites.Add(YourHostUrl + "/" + relativeUrl,
                                         item ["Title"].ToString (),
                                         item["Description"].ToString (),
                                         1033,
                                         item["Template"].ToString (),
                                         siteAdministratorLoginName,
                                         siteAdministratorName,
           ;                             siteAdministratorEmail);
         newWeb = site.OpenWeb();
         url = newWeb.Url;
         web.Dispose ();
         site.Dispose ();
       });
       } 
  catch (Exception ex)
   {
     // handle exception
    }
   finally
   {
      if (newWeb!= null)
       {
         newWeb.Dispose();
       }
       if (site != null)
       {
         site.Dispose();
        }
    }
return url;
}

 
Apply Business Process
Finally we can apply our business process. To help you to apply the business process, you will need to develop a Site Provision handler class, which contains your custom methods.
Developing an Site Provisioning Handler
Depending of your requirements you will develop your handler. Here is a list; to give you an idea of what kind of methods you can implements in your handler:

• Create unique permission levels – You can define a new permission set that contains your custom roles.
• Create new groups - You can create a new site group to include the rights you created.
• Add users or groups - You may want to add user to your new groups.
• Activate Features – Activate the right features for each template.
• Add Content – Add web parts, create pages edit content and etc.
• Set site quota
• Change StyleSheet
• …

When you develop the site provision handler make sure…
• You dispose SPSite and SPWeb and be sure there are no memory leaks.
• You test it with different user accounts that have only Reader rights.
• You handel collaboration sites and publishing sites differently (publishing site pages need to be checked out before editing)
• Error handling – You provide feedback to the user and log error information.

Created Sites List
Last but not least, create a list that contains all sites that were created with your site provision. This list will be useful to monitor exiting sites and most importantly you could execute CAML queries to retrieve sites from the list.

For example, if you want to display the last five sites that were created. You can do it simply by using this CAML query:
SPListItemCollection itemColl = null;
using (SPSite site = new SPSite (SPContext.Current.Site.Url))
{
   using (SPWeb web = site.OpenWeb ())
   {
     SPList list = web.Lists [“CreatedSitesList”]; 
     SPQuery qry = new SPQuery();
     qry.Query = "";
     qry.ViewFields = "";
     qry.RowLimit = 5;
     itemColl = list.GetItems(qry);
}
}
 
 

Conclusion
This article gives you some tips to create SharePoint sites programmatically, which enables custom business process automation. Hopefully it gave you a good start point for your site provision.

Comments

  1. Please remove all republished eggheadcafe.com content from your blog. We did not grant you permission to copy the work we paid our authors to do. A request has been submitted to google to force its removal.

    ReplyDelete

Post a Comment

Popular posts from this blog

Sharepoint 2010 Subsites webpart

This posting was originally made by Arild Aarnes and it is in here . This is a simple webpart to show a list (with links) of subsites immediately below the current site. This webpart will work on both Sharepoint 2010 and Sharepoint Foundation. On Sharepoint 2010 you could have used the built in “Table of Contents” webpart to do similar things but this one can also display the list as a dropdown list to save space on the webpage and it can open links in a new window. All the settings can by edited in the webpart configuration panel. The settings are: Show bullet in list – this will display the small square gif in front of the site name Open link in new window – this will open the subsite in a new window Show Site Description – this will show the description you entered when you created the subsite Show icon – Shows a icon for the type of subsite, see picture. Show as dropdown list – Will display the subsites in a dropdown box to save space. The webpart can be downl

Configuring the User Profile Service in SharePoint 2010

I will share with you my step by step guide in setting up the User Profile Service application, focusing on its configuration and administration and how we can enable the creation of user profiles via an Active Directory import . SharePoint 2010 introduces the notion of “Service Applications” which build’s upon the “Shared Services Provider (SSP)” which was introduced in SharePoint 2007.  Service Applications are individual services that can be configured independently and can be shared across other sites within your farm with some service applications that can also be configured across farms. The individual service applications provided with SharePoint 2010 are listed as follows; Access Services Business Data Connectivity Document Conversion Excel Services Managed Metadata Service PerformancePoint Search Service Secure Store State Service Visio Graphics Service User Profile Service This article will build upon our initial SharePoint 2010 install utilizing the least privi

The Text Filter Web Part – Without Having To Filter Exact Text

This posting I took it from  Here   This applies to both SharePoint 2007 and 2010.  In MOSS Enterprise, and the 2010 version of Enterprise.  There is an out-of-box web part called the Text Filter Web Part .  Basically, when you put this web part on a page, and put a list or library web part on the same page, you then create a web part connection that sends the text typed in the box as a filter to one of the columns in the web part, like this: The name Molly Clark had to be typed in exactly.  So, if you typed “Molly”, this record would not come up.  People use the text filter web part when they just want to search a single column in a list or library.  Otherwise, you’d simply use the “Search” box at the top of the screen, choose “This List” or “This Site” and perform SharePoint searches that way. One more note before I get into today’s solution: If you’re making use of site columns in your lists, there’s a setting where you can specifically select which columns you do N

Telephone format for a text box on infopath form

If you want to create a Telephone format on a infopath form : 1. Add a text field to the form (Even if it is the list or a blank form) 2. Select the text box and click on Manage Rules 4. Add a rule to your textbox control with the following conditions (make sure to select "and" operator):     a. field "does not match pattern" Phone number     b. the expression: string-length(translate(., "()- ", "")) = 10     c. the expression: string-length(translate(., "()- 0123456789", "")) = 0 5. Add action to the rule:     a. Set a field's value     b. Select your textbox field     c. Insert formula for the value (click the fx button): concat("(", substring(translate(., "()- ", ""), 1, 3), ") ", substring(translate(., "()- ", ""), 4, 3), "-", substring(translate(., "()- ", ""), 7, 4)) Link for the detailed explanation :  http:

HOWTO: change the home button text on the top link bar in sharepoint 2010

Hi All, I got a requirement that the title of the site collection which shows the first button on the top link bar to be different from the title. for example: my sharepoint site title is " Srikanth SharePoint Blog" and I need to show"Home" on the top link bar. It shows Home when the publishing features are not enabled. But once the publishing features are enabled it shows the same as the title("srikanth sharepoint blog" in my case instead of "Home").In other blogs I saw the solution as "in SITE ACTIONS>SITE SETTINGS>LOOK AND FEEL> TOP LINK BAR" , but once the publishing features are enabled, you don't see the "TOP LINK BAR" under "LOOK AND FEEL"(ofcourse it is changed to "NAVIGATION" , when publishing features are enabled). In this case : 1. Hide the initial button by adding code in css.    .s4-tn li.static > a{ display: none !important; } .s4-tn li.static > ul a{ display: bloc

SharePoint Branding and Design in 2010-2

Update: Really Small SharePoint Calendar I really was not that happy with the look of the first calendar so after some modifications and a bit of CSS magic I have come up with a really good looking small calendar. At least I think so… Basically I have replaced the text of an event item with a color coded box. The benefit that you get out of this is that you don’t have to try and read the even within the small calendar but if you hover over and click on the color block you get the list Item display. Orange is for single event items (8am-10am, etc) Green is for full day events or repeat events Another nice feature to this is that I have also simplified the visual indicator when there are more then two event items in one day. Instead of seeing the arrow and text all you see is the arrow. Once you click on the arrow it will show the other blocks of events (Right image). Here is the CSS Code: Download Here Simply place a content editor web part on the same page as the calendar

SharePoint Branding and Design in 2010

Hide First Tab in SharePoint 2010 Navigation I created a blog post on this for SharePoint 2007 HERE : But SharePoint 2010 is a bit more complex. Since it uses UL’s and Li’s for it’s navigation it is a bit harder to hide just one element. You will notice that the Home tab actually is the first node and then has a child UL which represents the rest of the navigation Items. So the approach is to hide the first <li> <a> (display: none) and then simply just use (display:block ) to show the hidden <ul> <li> <a> tags. Here is the CSS you could use to hide just the first node (home) tab in a SharePoint 2010 application: .s4-tn li.static > a{ display: none !important; } .s4-tn li.static > ul a{ display: block !important; } Enjoy! Posted by Erik Swenson at 12:12 PM 2 comments Labels: Branding , CSS , SharePoint 2010 Wednesday, August 18, 2010 How To: Hide Left Side Navigation on Home Page I was recently asked: " How can I hide the sid

Data View conditional formatting using SharePoint Designer

Data View conditional formatting using SharePoint Designer This article demonstrates how to use SharePoint Designer 2010conditional formatting to format items in a SharePoint (SPS 2010) list based on item metadata. The example uses a standard SharePoint task list and formats tasks based on the due date. The end result is a list view sorted by due date with item text or background coloured to represent the number of days until the due date. The Process In this example I have started with a standard task list and have created a few sample items for testing / demonstration. From the task list, create a new view, starting from the default “Active Items” view (filtered to only display incomplete tasks). The view created in the example is called “Active – Coloured” Open the view using SharePoint Designer. Right click on the List View Web Part and select “Convert to XSL Data View”. This will automatically convert settings for the current view into da