Tuesday, September 20, 2011

SharePoint 2010: Client Object Model: Content Type Development

To Create a content type using client object model, first create new Project using Console project Template. Add refrence to Microsoft.SharePoint.Client.dll and Microsoft.SharePoint.Client.Runtime.dll asemblies. You can find tyhen at {SharePoint Root}\ISAPI folder.

SharePoint code can run externally with help of ClientContext object. The ClientContext object provides access to site collection objects.

Code:

ClientContext clientContext = new ClientContext("http://anmol-pc");
Web web = clientContext.Web;


ContentTypeCollection contentTypes = web.ContentTypes;
clientContext.Load(contentTypes);
clientContext.ExecuteQuery();


ContentTypeCreationInformation newConInfo = new ContentTypeCreationInformation();
newConInfo.Name = "MyFirstContentType";
newConInfo.ParentContentType = contentTypes.GetById("add parent content ID");
newConInfo.Group = "My Group";
           
//Create
ContentType newContent = contentTypes.Add(newConInfo);
clientContext.ExecuteQuery();

No comments:

Post a Comment

Popular Posts