Tuesday, April 28, 2009

Allow user to download files of different types

Hi All,

here is code for you if you want the users to download file from your web page (as image,.xsls,.xslt etc).

*************** Code from here *******************

Response.ContentType = "image/jpeg";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + filename);
Response.TransmitFile(Server.MapPath("foldername" + filename));
Response.End();

*************** Till here *************************

Content-Type -- You can set the content-type according to your file......
as if it is jpeg then content-type will be "image/jpeg"
below is list of some of content-type :
MS Word file --- application/msword
straight binary --- application/octet-stream
xml,xslt files ---- application/xslt+xml
RTF document --- application/rtf
PDF document --- application/pdf
ZIP document --- application/zip

you can view more about these at the below link :

http://www.asptutorial.info/sscript/ContentType.html

No comments:

Post a Comment