档案下载ASP.NET [英] File download ASP.NET

查看:47
本文介绍了档案下载ASP.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我单击ASP.NET中的按钮时,我想将文件下载到我的计算机上,我要使用ASP.NET C#中的代码来实现此目的,也要说明如何使文件可访问,我的意思是

I want when i click a nutton in ASP.NET the file is downloaded to my computer, i want a code in ASP.NET C# to implement this , also about how can the file is made accessible to download,i mean where the file is put to download?

推荐答案

文件可能位于服务器的目录/虚拟目录中.在链接按钮中,具有指向文件的虚拟路径的链接.如果单击浏览器中的链接,则将下载文件.
The file could be in a directory/ virtual directory in your server. In a link button have a link of the virtual path pointing the file. If you click the link in the browser the file will get download.


http://msdn.microsoft.com/en-us/library/aa478985.aspx [ ^ ]

http://aspalliance.com/259_downloading_files__forcing_the_file_download_dialog [ ^ ]
http://msdn.microsoft.com/en-us/library/aa478985.aspx[^]

http://aspalliance.com/259_downloading_files__forcing_the_file_download_dialog[^]


使用此代码
Use this code
string filename = "site.css";// Need actual filename with extension E.g site.css
       Response.ContentType = "application/octet-stream";
       Response.AppendHeader("Content-Disposition", "attachment;filename=" + filename);
       Response.BinaryWrite(System.IO.File.ReadAllBytes(Server.MapPath("~/styles/" + filename)));
       Response.End();


这篇关于档案下载ASP.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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