当前位置: 代码迷 >> ASP.NET >> 請教ASP.NET1.1要實現下件的下載,在線等待.解决方案
  详细解决方案

請教ASP.NET1.1要實現下件的下載,在線等待.解决方案

热度:2812   发布时间:2013-02-25 00:00:00.0
請教ASP.NET1.1要實現下件的下載,在線等待..
在ASP.NET1.1中,要實現服務器上指定目錄下面的所有文件在頁面上顯示並能提供下載連接,要怎麼做呢?
有什麼好的方法沒有?
最好是有一個比較完整的代碼...........
謝謝...............

------解决方案--------------------------------------------------------
/// <summary>
/// 打开指定的文件
/// </summary>
/// <param name= "PathName "> 路径(相对路径) </param>
/// <param name= "FileName "> 文件名(带扩展名) </param>
public void OpenFile(string PathName, string FileName)
{
string name = PathName + FileName;
FileInfo aFile = new FileInfo(Server.MapPath(name));
string na = Path.GetFileName(name);
Response.Clear();
Response.ClearHeaders();
Response.BufferOutput = false;
Response.ContentType = "application/octet-stream ";
Response.AppendHeader( "Content-disposition ", "attachment;filename= " + HttpUtility.UrlEncode(FileName, Encoding.UTF8));
Response.AddHeader( "Content-Length ", aFile.Length.ToString());
Response.WriteFile(name);
Response.Flush();
Response.End();
}
------解决方案--------------------------------------------------------
string name = @ "e:\1.txt ";
FileInfo aFile = new FileInfo(name);
Response.Clear();
Response.ClearHeaders();
Response.BufferOutput = false;
Response.ContentType = "application/octet-stream ";
Response.AppendHeader( "Content-disposition ", "attachment;filename=1.txt ";
Response.AddHeader( "Content-Length ", aFile.Length.ToString());
Response.WriteFile(name);
Response.Flush();
Response.End();
  相关解决方案