第二个参数为要下载的文件的地址,第三个参数为文件名称。
public void DownloadFile(HttpResponse response, string serverPath,string fileName) { FileStream fs = null; try { fs = File.OpenRead(serverPath); byte[] buffer = new byte[1024]; long count = 1024; response.Buffer = true; response.AddHeader("Connection", "Keep-Alive"); response.ContentType = "application/octet-stream"; response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileName));//下载时要保存的默认文件名 response.AddHeader("Content-Length", fs.Length.ToString()); while (count == 1024) { count = fs.Read(buffer, 0, 1024); response.BinaryWrite(buffer); } response.End(); } finally { fs.Close(); } }