Vladimir Obrizan
Vladimir Obrizan

Reputation: 2593

SharePoint: how to get Internet media type of a document?

How to get Internet media type of a document using SharePoint web-services? I access the service using SOAP. I've tried the Content Types documentation, but it is something different than Conten-type/Internet media-type/MIME.

Upvotes: 1

Views: 1747

Answers (2)

Aviw
Aviw

Reputation: 1095

In case of server-side code you may use: SPUtility.GetMimeTypeFromExtension(".pdf")

Upvotes: 1

Dennis G
Dennis G

Reputation: 21788

SharePoint doesn't know about MIME-types. At least it doesn't know this on a per-file basis.

Check out SPFile which represents a file in SharePoint. The closest you might get is SPFile.ProgID: "Gets a string that identifies the application in which the file was created.", but that doesn't correspond to the MIME-type and nor is it always filled.

The MIME types are actually assigned by the IIS web server as you can see in this explanation:

enter image description here

So you will not be able to get the mime type by querying the SOAP web service. Your only chance is to download the file in question and check the HTTP Header in which you should find the Content-Type assigned by the IIS.

You won't be able to query by content type or similar stuff, you will have to use file extensions for that (e.g. xlsx, docx) - the IIS does nothing differently, it assigns the MIME-types by file extension. So instead of trying to get the mime-type, it might be easier to just get the file extension and deduct the mime-type from there.

Lastly: The SharePoint Content Type is a SharePoint internal construct. It represent different types of content in SharePoint, not always relating to downloadable documents. It has nothing to do with mime-types.

Upvotes: 3

Related Questions