Re: Auto detect content-type

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Kevin Spencer (kevin_at_DIESPAMMERSDIEtakempis.com)
Date: 02/07/05


Date: Mon, 7 Feb 2005 11:16:29 -0500

MIME types are usually recognized by the file extension. When the file
extension doesn't match the MIME type, the Response.ContentType header must
be set, to let the browser know. So, if you want to "autodetect" the MIME
type, you're going to have to do one of the following:

1. Read the file extension
2. Know what the type of file is by some other means

Then you have to set the Response.ContentType to that MIME type in the
Response.

-- 
HTH,
Kevin Spencer
Microsoft MVP
.Net Developer
Neither a follower nor a lender be.
"Grzegorz Kaczor" <grzegorz.kaczor@cc.com.pl> wrote in message 
news:cu829h$h0k$1@nemesis.news.tpi.pl...
> Hello,
>
> I wanted to use Response.TransmitFile to return an image instead of a HTML 
> page. Under IE everything works well, but under Mozilla/Firefox the image 
> is treated as it were text/html.
>
> When I set up content-type in response to image/jpeg everything works 
> well.
>
> But I would like to send any file instead of an image and thus I cannot 
> always know the proper content type. Is it possible to "autodetect" a file 
> content type? Or make IIS perform an "invisible redirect" (something like 
> Server.Execute but with local path name instead of URL) so that default 
> IIS mechanisms of content-type detection were used?
>
> Thanks
> Grzegorz Kaczor 


Relevant Pages

  • Re: File associations
    ... a File Extension - If there isn't actually a File Extension on the ... If you do want to Create any particular File Association, ... & Internet Explorer actually just *ignores* the MIME Type ...
    (uk.people.silversurfers)
  • Re: Website for info on improving digital signal?
    ... > Using the Opera browser it downloads on my machine as 'txpath.ps'. ... > Most users of Windoze will have hidden the file extension* and will ... I just tried it and firefox saw it as txpath.exe, with a mime type ... So it saved it as txpath.exe (with no hidden extension). ...
    (uk.tech.digital-tv)
  • Re: TXT or HTML? -- IE NEW BUG
    ... file extension supercedes MIME type in IE. ... I have noted several cases where servers were misconfigured, ... I have also noted that cgi-generated PDF files are not handled correctly ...
    (Bugtraq)
  • Re: outlook express attachments
    ... that sends me the stuff to switch to a different email program, ... In OE this would be an EML file. ... OE uses the MIME type to determine the file extension. ...
    (microsoft.public.windows.inetexplorer.ie6_outlookexpress)