You are viewing limited content. For full access, please sign in.

Question

Question

Using RA, how to determine the content type of a file to be attached to an entry

asked on January 31, 2014

I see the DocumentImporter class has two methods (both called ImportEDoc) which require the MIME content type of the file to attach to the entry.

 

Is there a way to establish the content type of the document you want to import, or is there a content type that "covers all"?

 

0 0

Answer

APPROVED ANSWER
replied on February 2, 2014

I found this code snipit which works perfectly:

 

       private string GetMimeType(FileInfo fileInfo)
        {
            string mimeType = "application/unknown";

            RegistryKey regKey = Registry.ClassesRoot.OpenSubKey(
                fileInfo.Extension.ToLower()
                );

            if (regKey != null)
            {
                object contentType = regKey.GetValue("Content Type");

                if (contentType != null)
                    mimeType = contentType.ToString();
            }

            return mimeType;
        }

1 0

Replies

replied on January 31, 2014

What is your situation that you don't know the mime type of the documents you are importing?  Applications in Windows typically register mime types for file extensions, which you can access with GetMimeMapping or by reading the registry directly.  If this is a web application, file uploads include the mime type.  If you really don't know, "application/octet-stream" is kind of the default, but everything will work better if you store the correct mime type.

2 1
replied on January 31, 2014 Show version history

There are several ways to do this.  The answers to the following post give many examples.

 

http://stackoverflow.com/questions/58510/using-net-how-can-you-find-the-mime-type-of-a-file-based-on-the-file-signature

0 0
replied on February 2, 2014

Thank you!

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.