在下载页面加载事件文件? [英] Downloading file in Page load event?

查看:102
本文介绍了在下载页面加载事件文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能下载文件[点击没有任何按钮或链接或锚标记]在页面加载事件,我想下载的页面加载它自身的文件,请helpe我,谢谢

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

推荐答案

假设你有一个文件在磁盘上被下载和具有路径它。继code会做的伎俩。

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);

这篇关于在下载页面加载事件文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆