Get ContentType

  • Thread starter Thread starter shapper
  • Start date Start date
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
 
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
 
Back
Top