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. :-)