Condividi tramite


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

  • Anonymous
    April 21, 2009
    PingBack from http://asp-net-hosting.simplynetdev.com/sharepoint-copyintoitems-and-setting-a-document-content-type/
  • Anonymous
    September 07, 2014
    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.
  • Anonymous
    September 07, 2014
    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.
  • Anonymous
    October 07, 2014
    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...