开发者

Downloading file in Page load event?

How can i download a file [without click any button or link or anchor tag ]in page load event, I want to download a 开发者_运维百科file in a page load it self, please helpe me, thank you


Assuming you have the file to be downloaded on the disk and has path for it. Following code will do the trick.

// You should put more appropriate MIME type as per your file time - perhaps based on extension
Response.ContentType = "application/octate-stream"; 
Response.AddHeader("content-disposition", "attachment;filename=[your file name w/o path]");
// Start pushing file to user, IIS will do the streaming.
Response.TransmitFile(filePath);


In your Page_Load method add following lines, set the appropriate content type and replace yourfile.extention with the full name of file that you want to be downloaded.

this.context.Response.ContentType = "application/filetype";
this.context.Response.AddHeader("content-disposition", "attachment;filename=yourfile.extension");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜