Apr 3, 2012

Client Object Model Part -2

In this post we will create some examples using Managed Client Object model. Our objective here is to create the Web, List, Add Items, Update Items, Delete Items etc using the Managed COM. Please go through the Part -1 for understanding the basics of COM
Create Web :
//Create web in the root site.
            using (ClientContext clientContext = new ClientContext(SiteURL))
            {
                WebCollection webColl = clientContext.Web.Webs;
               
                WebCreationInformation newWebCreationInfo = new WebCreationInformation();
                newWebCreationInfo.Title = "New web site";
                newWebCreationInfo.Description = "Here goes the description ";
                newWebCreationInfo.Language = 1033;
                newWebCreationInfo.Url = "NewWeb1";

                newWebCreationInfo.UseSamePermissionsAsParentSite = true;
               //This template is for team site
                newWebCreationInfo.WebTemplate = "STS#0";

                Web oNewWebsite = webColl.Add(newWebCreationInfo);
                clientContext.ExecuteQuery();
            }

So this code snippet will create the web (Team site)inside a site collection. We can create any site by specifying the required WebTemplate type. Here is the list of available templates.
List of Web Templates :

                    Template ID     Template Name
                    GLOBAL#0      Global template
                    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
                    CENTRALADMIN#0    Central Admin Site
                    WIKI#0      Wiki Site
                    BLOG#0      Blog
                    SGS#0       Group Work Site
                    TENANTADMIN#0    Tenant Admin Site
                    ACCSRV#0      Access Services Site
                    ACCSRV#1      Assets Web Database
                    ACCSRV#3      Charitable Contributions Web Database
                    ACCSRV#4      Contacts Web Database
                    ACCSRV#6      Issues Web Database
                    ACCSRV#5      Projects Web Database
                    BDR#0       Document Center
                    OFFILE#0      (obsolete) Records Center
                    OFFILE#1      Records Center
                    OSRV#0      Shared Services Administration Site
                    PPSMASite#0    PerformancePoint
                    BICenterSite#0     Business Intelligence Center
                    SPS#0       SharePoint Portal Server Site
                    SPSPERS#0     SharePoint Portal Server Personal Space
                    SPSMSITE#0     Personalization Site
                    SPSTOC#0      Contents area Template
                    SPSTOPIC#0     Topic area template
                    SPSNEWS#0     News Site
                    CMSPUBLISHING#0   Publishing Site
                    BLANKINTERNET#0   Publishing Site
                    BLANKINTERNET#1   Press Releases Site
                    BLANKINTERNET#2   Publishing Site with Workflow
                    SPSNHOME#0     News Site
                    SPSSITES#0     Site Directory
                    SPSCOMMU#0     Community area template
                    SPSREPORTCENTER#0  Report Center
                    SPSPORTAL#0     Collaboration Portal
                    SRCHCEN#0     Enterprise Search Center
                    PROFILES#0     Profiles
                    BLANKINTERNETCONT...  Publishing Portal
                    SPSMSITEHOST#0    My Site Host
                    ENTERWIKI#0     Enterprise Wiki
                    SRCHCENTERLITE#0  Basic Search Center
                    SRCHCENTERLITE#1  Basic Search Center
                    SRCHCENTERFAST#0   FAST Search Center
                    visprus#0      Visio Process Repository

Note: For creating publishing webs, make sure publishing features are enabled on the parent site.
Happy Coding J
Continue reading Part -3

No comments:

Post a Comment