日期:2014-05-19  浏览次数:20469 次

急请助!vs studio 2005如何下载网站中其中一个文件?
我想点击一个buttom,下载网站中其中一个指定文件,要如何实现?各位有什么高见,谢谢.在线等待.谢谢

------解决方案--------------------
string filename = "a.txt ";

if (filename != " ")
{

string path = Server.MapPath(filename);

System.IO.FileInfo file = new System.IO.FileInfo(path);

if (file.Exists)
{

Response.Clear();

Response.AddHeader( "Content-Disposition ", "attachment; filename= " + file.Name);

Response.AddHeader( "Content-Length ", file.Length.ToString());

Response.ContentType = "application/octet-stream ";

Response.Filter.Close();

Response.WriteFile(file.FullName);


Response.End();

}

else
{

Response.Write( "This file does not exist. ");

}

}