當您將NavigateUrl設置爲FullPath時,Chrome將會看到訪問站點的用戶計算機的本地鏈接,而不是服務器本身。
所以,你總是需要使URL任何hyberlink是在// someURL的形式或http://someurl
你的情況,你必須刪除NavigateUrl
並添加OnClick
處理程序,並在裏面處理程序中,你將使用FILESTREAM讀取文件和寫入文件內容響應流然後刷新它的點擊處理程序的
例如:
context.Response.Buffer = false;
context.Response.ContentType = "the file mime type, ex: application/pdf";
string path = "the full path, ex:E:\PINCDOCS";
FileInfo file = new FileInfo(path);
int len = (int)file.Length, bytes;
context.Response.AppendHeader("content-length", len.ToString());
byte[] buffer = new byte[1024];
Stream outStream = context.Response.OutputStream;
using(Stream stream = File.OpenRead(path)) {
while (len > 0 && (bytes =
stream.Read(buffer, 0, buffer.Length)) > 0)
{
outStream.Write(buffer, 0, bytes);
len -= bytes;
}
}
這是不可能的。 –
使用linkbutton;爲按鈕添加事件處理程序;在服務器端打開文件(使用'Server.MapPath方法');然後作爲pdf流。更好的是,如果可能的話,將該文件複製到靜態資源目錄中並使用普通超鏈接。 – mshsayem
讓客戶端下載一個你需要一個url的文件,首先你需要將你的服務器本地路徑轉換爲一個url 這裏是一個鏈接來做 http://stackoverflow.com/questions/16007/how-do-i -convert-a-file-path-to-a-url-in-asp-net – Kiarash