0

first off: big fan of this site and have always found a solution to a problem when visiting here. I have a small problem when using the Client Object Model for Sharepoint 2010: I am trying to set the Content Type of an item, however it keeps reverting back to it's original ContentTypeId after I call the "Context.ExecuteQuery()". Here is a sample of the code:

    item["ContentTypeId"] = targetContentType.Id.ToString();
    item.Update();
    destinationContext.ExecuteQuery();

If I step through the code and check the ContentTypeId I can that it has changed but as soon as I hit ExecuteQuery it reverts back to the original Content Type. The item in question sits in a sub-folder of the document library and is a docx file. The Content Type itself does exist. If I run the same code on any other file type, e.g: htm; it changes the content type successfully.

Michael
  • 8,920
  • 3
  • 38
  • 56
  • Should it be just targetContentType.Id ?? – Jinxed Oct 10 '13 at 09:30
  • Nope, .ToString() is correct as the type of item["Field"] is String. The code works for other items being inserted into the document library but just doesn't seem to like docx files for some reason. – Mephistolis Oct 10 '13 at 09:48

1 Answers1

0

You can never change an content type id.(Similar to Column ID)

When you change the name of a content type, it's content type id will keep the same.

And you may check the content type id in the URL for the param ctype:

http://bernadonguyenhoan.files.wordpress.com/2011/04/content-type-id.png

Tony Wu
  • 1,040
  • 18
  • 28