因為下載的同時要更新數(shù)據(jù)庫的信息,所以直接寫在超鏈接里就不行了.用window.openIE有的 版本還不支持.后來想到用一個aspx頁面后臺處理下載,用流的方式,但有一個問題是 要下載的文件和網(wǎng)站不在同一機器.地址是類似http://...../a.zip這樣的話,FileStream似乎不支持網(wǎng)絡(luò)路徑.代碼如下: string fileName = strName;//客戶端保存的文件名 string filePath = "http://.....//a.zip";//路徑 //以字符流的形式下載文件 FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate,FileAccess.Write); byte[] bytes = new byte[(int)fs.Length]; fs.Read(bytes, 0, bytes.Length); fs.Close(); Response.ContentType = "application/octet-stream"; //通知瀏覽器下載文件而不是打開 Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8)); Response.BinaryWrite(bytes); Response.Flush(); Response.End();怎么辦,有什么好辦法.
- 2 回答
- 0 關(guān)注
- 710 瀏覽
添加回答
舉報
0/150
提交
取消