使用WebClient
在下载按钮事件中加入如下代码
System.Net.WebClient wc = new System.Net.WebClient();
wc.DownloadFile( "http://localhost/a.gif", "c:\a.gif");
上述代码会把服务器端的a.gif文件在没有任何提示的情况下下载的客户端的c盘,没有任何提示还是比较可怕的,不过有的时候确实需要这样做。该代码也可以在桌面程序运行
解决方案 »
- 哪位能详解讲一下Route.GetVirtualPath方法
- 如何链接到不同的页内容并显示在同一链接页上
- 如何判断textbox用户输入的数字长度
- 不内联代码,不用Codebehind,不做成控件,不预编译,不用模板引擎,如何才能在发布网站时不必发布如aspx相对应的cs文件
- 我想取出字段里是数字的记录。sql语句,应该怎么写啊?
- 在FreeTextBox里,如何取得不带html标识的纯文本?
- 能否在WinForm中设置Web Application中的Cache?
- 关于DLL文件?!
- 水晶报表是MVS.NET自代的CRYSTALREPORTVIEWER吗?
- Microsoft Developer 开发工具发展规划图 2002–2004
- 千万级数据分页,讨论
- <%# Eval("Name","~/images/{0}") %> 想将"~/images/{0}"这部分改成变量怎么做,谢谢!
您的代码还是只能下载到服务器上面不能下载到本地机器.
TO:WO_YOU_XIE_SHANG_XIN
需要功能不一定全是写病毒,只是想要这样功能如何才能实现....
这种需求实际用的时候需要很多,但看到的都是下载到服务器上面.....
请求高手解答!~
System.EventArgs e)
{
FileInfo file;
String filename; //get the fully qualified name of the selected file
filename = Server.MapPath("images") + "\\" +
lstFiles.SelectedItem.Text; // get the file data since the length is required for the download
file = new FileInfo(filename); // write it to the browser
Response.Clear();
Response.AddHeader("Content-Disposition",
"attachment; filename=" + lstFiles.SelectedItem.Text);
Response.AddHeader("Content-Length",
file.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.WriteFile(filename);
Response.End();
} // btnDownload_ServerClick