SharePoint CopyIntoItems and Setting a Document Content Type


I can’t take credit or this one, but a colleague I have been working with was able to figure this out.  He doesn’t blog, so I am sharing it with the greater community.  Our quest was to upload a document into a document library using the Copy.asmx web service and set the content type on the document as well as other field information as part of the upload.  The method takes a FieldInformation array, so at first glance this seemed like it was going to be pretty easy.  We all know what happens next.

Initial attempts were successful at uploading, but not setting the content type.  The content type would always end up as Document, the default.  We tried several different variations, but nothing worked.  There are also others that seem to have had the same fate and come up with other workarounds.

My colleague had the idea to call the GetItem() method for an item that had the content type already set, and there was the answer.  The type of field for a content type is FieldType.Choice, not FieldType.Text, which was the assumption all along.  Calling GetItem() returned the following:

<FieldInformation Type="Choice" DisplayName="Content Type" InternalName="ContentType" Value="***"/>

From there it was straightforward.  Uploading and setting the content type in one simple method call.  He asked that I give his company a plug, so … those people at SAS are pretty smart aren’t they. 🙂

Comments (4)
  1. Setting Document Content Type using Copy.asmx says:

    Hi,

    As per my analysis, if we need to set the Custom Content Type, ContentTypeID is mandatory to be shared thru FieldInformation and it is FieldType.Text in SP2013.

    We can get the ContentTypeID using the Web Method GetContentTypes() in SP Service Web.asmx.

  2. Setting Document Content Type using Copy.asmx says:

    Hi,

    As per my analysis, if we need to set the Custom Content Type, ContentTypeID is mandatory to be shared thru FieldInformation and it is FieldType.Text in SP2013.

    We can get the ContentTypeID using the Web Method GetContentTypes() in SP Service Webs.asmx.

  3. GeertH says:

    Thanks a lot  for all those hints!

    After a little further investigation, for us (SP2010, probably a dutch version) only following combination worked:

    FieldInformation contentTypeInfo = new FieldInformation();

    contentTypeInfo.setDisplayName("Inhoudstype-id");

    contentTypeInfo.setType(FieldType.TEXT);

    contentTypeInfo.setValue("0x0101001D…etc…");

    fields.getFieldInformation().add(contentTypeInfo);

    … call tocopyIntoItems…

Comments are closed.

Skip to main content