Get ContentType

S

shapper

Hello,

How can I get the content type of a file given its path?
I know how to use Path to get the filename but not the content type.

Can I get the file into a File object?

Thanks,
Miguel
 
P

Peter Duniho

How can I get the content type of a file given its path?
I know how to use Path to get the filename but not the content type.

Can I get the file into a File object?

System.IO.File is a static class. There's no such thing as "a File
object", if that's the class you're talking about. And if it's not, you
should be more clear about what class you mean.

As for content type, again...you should be more clear. But, I assume you
are talking about the MIME type for a file? If so, I'm not aware of
anything in .NET that does that. The Windows Explorer maintains file
association information, and I'm pretty sure there's an unmanaged API to
retrieve that. It's possible you can use WMI from .NET to get the same
information; that's technically managed code, even if all it does is go
through the unmanaged data structures. :)

Note that not all files will have an associated MIME type.

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top