protected void DownLoadFile(String filePath, string fileName) { if (fileName == "") { fileName = FileOperate.GetFileName(filePath); } filePath = Server.MapPath(filePath); var file = new System.IO.FileInfo(filePath); if (System.IO.File.Exists(filePath) & filePath.Contains("upload")) { Response.Clear(); Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName)); Response.AddHeader("Content-Length", file.Length.ToString()); Response.ContentType = "application/octet-stream"; //Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8"); Response.WriteFile(file.FullName); Response.Flush(); //Response.End(); } else { Response.Write("附件不存在!"); Response.Flush(); } }
protected void ShowFileName(String inFilePath, String fileName) { if (fileName == "") { fileName = FileOperate.GetFileName(inFilePath); } this.divFileName.InnerText = fileName; }
protected void ResponsePreview(String pdfFilePath) { string fileName = FileOperate.GetFileName(pdfFilePath); Response.ContentType = "Application/pdf"; Response.AddHeader("content-disposition", "filename=" + fileName); Response.WriteFile(Server.MapPath(pdfFilePath)); Response.End(); }
protected void ResponsePreview(string inFilePath) { string fileName = FileOperate.GetFileName(inFilePath); Response.ContentType = "text/plain"; Response.ContentEncoding = System.Text.Encoding.UTF8; //保持和文件的编码格式一致 Response.AddHeader("content-disposition", "filename=" + fileName); Response.WriteFile(Server.MapPath(inFilePath)); Response.End(); }