tags:

views:

44

answers:

1

I have a user that has requested the ability to add files from a custom web site that will upload a file and populate the content types. I have the first part done, uploading the file. I do not know how to read the possible content types and how to update the content types for the specific file being uploaded.

A: 

Your question is not very clear - files external to sharepoint do not have a predictable content type. It's not like file extension associations, where .exe is always an executable, and .gif is always an image. Within sharepoint, the only limitation for files' content types is that the content type inherit from the Document content type. The association you make with any given type of file must be invented by you

As for finding out what content types exist on a document library, examine the SPList instance's .RootFolder.ContentTypes property.

Secondly, to set the content type on a file that has been uploaded you will most likely have to develop an Event Receiver which is a class derived from SPItemEventReceiver. You can trap the ItemAdded event and set the file's content type programmatically. This is done by setting one of it's internal properties to the ID of one of the SPContentType's retrieved in the earlier step.

-Oisin

x0n