当点击文件链接对象时,弹出对话框让用户选择是打开还是另存为本地文件的实现方法。
//
value为文件路径
string tmpFileName = value;
FileInfo tmpFI = new FileInfo(tmpFileName);
Response.Clear();
Response.ClearHeaders();
Response.Buffer = false ;
Response.AppendHeader( " Content-Disposition " , " attachment;filename= " + HttpUtility.UrlEncode(Path.GetFileName(tmpFileName), System.Text.Encoding.UTF8));
Response.AppendHeader( " Content-Length " , tmpFI.Length.ToString());
Response.ContentType = " application/octet-stream " ;
Response.WriteFile(tmpFileName);
Response.Flush();
Response.End();
string tmpFileName = value;
FileInfo tmpFI = new FileInfo(tmpFileName);
Response.Clear();
Response.ClearHeaders();
Response.Buffer = false ;
Response.AppendHeader( " Content-Disposition " , " attachment;filename= " + HttpUtility.UrlEncode(Path.GetFileName(tmpFileName), System.Text.Encoding.UTF8));
Response.AppendHeader( " Content-Length " , tmpFI.Length.ToString());
Response.ContentType = " application/octet-stream " ;
Response.WriteFile(tmpFileName);
Response.Flush();
Response.End();