Often you get a requirement from user to create SharePoint site for them. You are flooded with 1000's of such user request, and you don’t have time to work on each of the request. SharePoint Object model is there to help you out. How?
Using SharePoint Object model you can create SharePoint Site programmatically.
· Create a SharePoint Web Part which will take required information from user for the site like Site Name, Site Language, Site template(See table below)
· Use above information and once user has submitted all required information run the SharePoint API to create a SharePoint site.
Let’s see the code now which can be written inside Web Part.
SPSite site = SPContext.Current.Site;
SPWeb web = site.OpenWeb();
SPWebCollection sitesCollection = web.Webs;
SPWeb webSite = sitesCollection.Add("sitename", "Description of the Site", "This is site created programmatically.", 1033, "STS#2", true, false);
That’s it. You have just crated a SharePoint site using SharePoint Object model.
Let’s understand few important parameters from above code.
Below are Site Definitions used to create a Site with pre-defined template.
Value | Site Definition |
STS#0 | Team Site |
STS#1 | Blank Site |
STS#2 | Document Workspace |
MPS#0 | Basic Meeting Workspace |
MPS#1 | Blank Meeting Workspace |
MPS#2 | Decision Meeting Workspace |
MPS#3 | Social Meeting Workspace |
MPS#4 | Multipage Meeting Workspace |
WIKI#0 | Wiki |
BLOG#0 | Blog |
1033 is to create Site in English Language.
No comments:
Post a Comment