private void Page_Load(object sender, System.EventArgs e)
{
      // 在這裡放置使用者程式碼以初始化網頁
      string path = Request.QueryString["file"] == null ? "" : Request.QueryString["file"];
      if(path != "")
     {
   
        System.Net.WebClient webclient = new System.Net.WebClient();
        byte[] b = webclient.DownloadData(path);
        string Filename = System.IO.Path.GetFileName(path);
        Response.AddHeader("Content-Disposition",string.Format("{0}; filename={1}","attachment",Filename));
        Response.BinaryWrite(b);
   
     }

}

//標頭Content-Disposition的設定:attachment表示指定檔案是附件型式,inline表示指定檔案是內崁網頁中,即是預設狀態

//建立一下載程式頁,專門處理下載檔案,網址規格 http:// [url] / [aspx程式檔]?file=[path],

//[path]:指定下載檔案位置

arrow
arrow
    全站熱搜

    crazylv 發表在 痞客邦 留言(0) 人氣()