Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I need to create custom content type from a given guid for a SharePoint site using Client Object Model. However, in the constructor of

ContentTypeId ctid = new ContentTypeId()

there is no facility to provide value for GUID.

If one notices server side object model to perform the same operation as per http://msdn.microsoft.com/en-us/library/ff798370.aspx then there is an option to provide GUID in the constructor as

SPContentTypeId myContentTypeId = new SPContentTypeId("0x010100FA0963FA69A646AA916D2E41284FC9D9");

Why there is such a difference between Client Object Model and Server Object Model? Is there any possible work around?

share|improve this question
add comment

1 Answer

It's not possible to set the content type id in CSOM. Not sure why the difference. The closest you can get is setting the ParentContentType value, but that leaves the final two digits to be randomly generated. This is how to create a content type in CSOM:

var clientContext = new ClientContext( siteUrl );
// For SharePoint Online
var credentials = new SharePointOnlineCredentials(login, secureStringPassword);
clientContext.Credentials = credentials;

var contentTypes = clientContext.Web.ContentTypes;
var contentTypeCreationInformation = new ContentTypeCreationInformation
                                     {
                                         Name = "Content Type Name",
                                         Description = "Description",
                                         Group = "Group",
                                         ParentContentType = ContentType // Must be content type object
                                     };
var contentType = contentTypes.Add( contentTypeCreationInformation );
clientContext.Load( contentType );
clientContext.ExecuteQuery();
clientContext.Dispose();
share|improve this answer
    
This code does not give the option to provide the Content type ID either though –  Robert Lindgren Jun 16 at 13:46
1  
CSOM doesn't provide a method to set the ID on creation. The closest is setting the ParentContentType parameter, but that still leaves the last two digits to random. –  wjervis Jun 16 at 13:48
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.