日期:2014-05-18  浏览次数:20405 次

請教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();