• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 276
  • Last Modified:

Getting Content-Type of a File

Hi experts,

I want to detect the content type of a file. I have a dll to "force download" of a file, but I couldn't figure out how to get the content-type. I imagine there should be a way to find it.

All answers are appreciated.

Thanks,
Igal NASSI
0
igalnassi
Asked:
igalnassi
  • 5
  • 2
  • 2
  • +1
1 Solution
 
pkmnfrkCommented:
Do you mean from a web site? Or off the HD?

If you mean HD, then you need to use an API call to find out. I don't know which one, but...

If you mean off the web, then you should be able to use the Mime type, but I don't usually do web stuff in VB.

Regardless, you could just check the extension of the file...
0
 
igalnassiAuthor Commented:
When I try to force the file to download from a web server, I should be sending the content-type in the response header. That's what I am trying to do. I don't think there would be any problems if I leave it blank, but I just don't want to take the chance for later versions of IE and netscape

Any other thoughts?
Igal
0
 
BuchankasCommented:
Well, you could use a Sniffer, I use http://www.ufasoft.com/sniffer

Just Start the Sniffer, open your browser, and click the link to the file, then the HTTP headers should be shown in the Sniffer.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
igalnassiAuthor Commented:
Maybe I didn't quite explain correctly. My program is writing the header. It just needs to rearrange the content-type of the header with regards to the file it needs to send to the browser... Say: image/gif for .gif files. I am trying to automatically detect the type of the file from my program
0
 
BuchankasCommented:
Hope this list helps, if you want to know any MIME type unlisted here let me know.



# Usual MIME types



text/plain                   txt cgi java

text/html                    htm html shtml

application/octet-stream     bin class

application/postscript       ps eps ai

application/pdf              pdf



# Image specific MIME types



image/x-xbitmap              xbm

image/x-xpixmap              xpm

image/x-xwindowdump          xwd

image/x-xbitmap              xbm

image/x-cmu-raster           ras

image/x-portable-anymap      pnm

image/x-portable-bitmap      pbm

image/x-portable-graymap     pgm

image/x-rgb                  rgb

image/gif                    gif

image/jpeg                   jpeg jpe jpg

image/tiff                   tiff tif


 
 
 # Audio video specific MIME types



audio/basic                 au snd

audio/x-wav                 wav

video/mpeg                  mpeg mpe mpg

video/quicktime             mov qt

video/x-sgi-movie           movie

application/java            java

application/x-csh           csh

application/x-sh            sh

application/x-tcl           tcl

application/x-tex           tex

application/x-latex         latex

application/x-texinfo       texinfo texi

application/zip             zip

application/x-bcpio         bcpio

application/x-cpio          cpio

application/x-shar          shar

application/x-tar           tar

application/x-dvi           dvi

application/x-hdf           hdf

application/x-x509-ca-cert  cer cert



# zip files



multipart/x-zip             zip

 
0
 
igalnassiAuthor Commented:
This list will help if I want to HARD-CODE the types. Is there a way to find it in the code?

In other words I want a function like this:

Private Function getMimeType(ByVal strExtension As String) As String




End Function
0
 
igalnassiAuthor Commented:
This list will help if I want to HARD-CODE the types. Is there a way to find it in the code?

In other words I want a function like this:

Private Function getMimeType(ByVal strExtension As String) As String




End Function
0
 
igalnassiAuthor Commented:
Sorry pressed submit by accident...

The inside of the function reads...

Private Function getMimeType(ByVal strExtension As String) As String

   Goto the registry or whereever you can find this info
   Find the mime-type
   getMimeType = mime-type just found

End Function


I don't want to hard code the MIME-TYPES in the function. I want to look for them from their source.
0
 
pkmnfrkCommented:
not really. The mime type was important for Netscape a while back, but is really redundant now. IE and NS both look in the registry for information on how to deal with a file. It should be quite safe to leave it blank.
0
 
CleanupPingCommented:
Hi igalnassi,
This old question (QID 20567997) needs to be finalized -- accept an answer, split points, or get a refund.  Please see http://www.cityofangels.com/Experts/Closing.htm for information and options.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 5
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now