In Sharepoint, there's a cool features that enable users to create their own sites without having to much dependencies to IT folks. Then the site might be use as a simple project workspaces, they can store a number of supporting documents, tasks, agenda and team member within the site. You can enable this features here...

However, there are a number of reasons why you want to create an ad hoc sharepoint site. I give you an example on certain scenarios that I've met that requires this automation process :

- There were time when you need to automate the process of sharepoint site creation the moment you receive a leads transfer from your vendor. Once the leads transferred, you want to ensure the notification will be sent by email to responsible parties and at the same time, the notification contains a link to a site that can be use as a workspace.

- Another example in project management, whenever a new project being created - you want to make sure the system also provide a corresponding Sharepoint site automatically on the fly. The site may automatically loaded with a set of project document files that usually being use as a template or references (Proposal template, presentation, schedule sheet, etc..)

You need to review the following checklist prior deploying the apps :

- Enable Self Service Creation features in Sharepoint
- Disable the Security Page Validation in Sharepoint Administration Console
- Deploy the apps in SPS Web Pool (in this example I deploy it in C:\Program Files\Common Files\Microsoft Shared\web server extensions\60\TEMPLATE\LAYOUTS\1033)

And here's the code that I use, you can use it as a touch base and alter it

SPWeb web = SPControl.GetContextWeb(Context);
       web.AllowUnsafeUpdates = true;
      
SPSite site = SPControl.GetContextSite(Context);
      
site.AllowUnsafeUpdates=true;
       string url = site.Url + "/sites/YOUR_SITE_HERE";
       
string title = "YOUR_TITLE_HERE";
      
string description = "YOUR_DESC_HERE";
      
string siteTemplate= "STS";

                     string owner1UserName = web.CurrentUser.LoginName;
 
                    string owner1DisplayName = web.CurrentUser.Name;
 
                    string owner1Email = web.CurrentUser.Email;

                     string owner2UserName = "";
 
                    string owner2DisplayName = "";
 
                    string owner2Email = "";

                     SPSite ssc =  site.SelfServiceCreateSite(url,title,description,1033,siteTemplate,owner1UserName,
                        
owner1DisplayName, owner1Email,
owner2UserName, owner2DisplayName, owner2Email);

 

 Jakarta