473,326 Members | 2,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Determining ContentType for binary attachments

I have seen many examples on the web for downloading attachments ffrom
ASP.NET forms using response.WriteBinary, but they all use hard-coded
ContentTypes (for example, Response.ContentType = "application/pdf"). Is
there a good way to "guess" the content type for arbritary file name? Every
web server has a mapping from file extension to content type, but how do I
get this from ASP.NET? Thanks!
Nov 19 '05 #1
2 3996
Could use a huge CASE statement with the extensions for the files and the
content type normally associated.

--
Curt Christianson
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Stephen Walch" <sw****@online.nospam> wrote in message
news:eg**************@TK2MSFTNGP09.phx.gbl...
I have seen many examples on the web for downloading attachments ffrom
ASP.NET forms using response.WriteBinary, but they all use hard-coded
ContentTypes (for example, Response.ContentType = "application/pdf"). Is
there a good way to "guess" the content type for arbritary file name?
Every web server has a mapping from file extension to content type, but how
do I get this from ASP.NET? Thanks!

Nov 19 '05 #2
Hi Stephen,

In addition to Curt_C's suggestion on use a huge CASE to determine the
file's contenttype accroding to the filename extention, you can also
consider use the 'application/octet-stream' as a common value if you're not
sure about the exact MIME TYPE of your filestream. Here is the msdn
reference on how IE browser detect the download stream's content Type:

http://msdn.microsoft.com/library/de...tworking/monik
er/overview/appendix_a.asp

Hope also helps.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Bill | last post by:
I'm using the example shown at : http://support.microsoft.com:80/support/kb/articles/q276/4/88.asp It involves using ASP/VbScript and ADODB.Stream to read binary data from a *.DOC or *.RTF file...
9
by: Maurizio Penna | last post by:
I, guys. I've embeded an image into a xml file, something like that: <display type="picture" mime="image/png" name = "mosaico6.png"> <!]> </display> Now, I want to display it with a XSL...
0
by: CTDev Team | last post by:
Hi, We are using Exchange Server 5.5, and have applications written in VB6 and C# that read and process emails. We are experiencing intermittent errors similar to C# Application ...
4
by: Alex Vincent | last post by:
HI all, I'm storing images, jpgs/gifs/png/bmps and also some other binary files in a SQL image field in a SQL 2k database. Most of the images enter the database via a asp.net webform upload,...
2
by: Ryan Taylor | last post by:
Hello. I have an ASP.NET application where I allow the user to upload attachments. I upload the attachments as binary data to an image column in sql server. I have managed to upload the data...
5
by: David Lozzi | last post by:
Hello, this is a repost of a previous post of mine from today. I need to export multiple documents (doc, xls, ppt, jpg) and crystal reports to a single PDF file. I know how to export a single...
7
by: darrel | last post by:
I'm creating a file upload tool, and want to allow only DOC, XLS, PDF, RTF or TXT files. I am using this to check: if (contentType = "application/msword") _ or (contentType = "application/rtf")...
1
by: Nathan Sokalski | last post by:
I am having trouble determining the MIME type of a file. Does anybody know how to do this for a file programmatically? Thanks. -- Nathan Sokalski njsokalski@hotmail.com...
4
by: fred80 | last post by:
Hello This is my first post here :) I have a table that hold attachments in binary format. The problem started when i've been asked to write a code that send an email that have all these file as...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.