最近项目需要做电子签章,需要网页打开PDF签章后保存:正好复习哈二进制和流的转换:

  文件转换成二进制字符串写入HTTP输出流

 1  protected void Page_Load(object sender, EventArgs e)
 2         {
 3             try
 4             {
 5                 string path = "Tett.PDF";           //获取文件名
 6                 path = Server.MapPath(path);        //获取物理文件路径
 7                 if (File.Exists(path) == false)
 8                     throw new Exception("找不到PDF文件");
 9                 FileStream fs = File.Open(path, FileMode.Open);
10                 byte[] buffer = new byte[fs.Length];
11                 fs.Read(buffer, 0, buffer.Length);
12                 fs.Close();
13                 Response.ContentType = "application/pdf";
14                 Response.AddHeader("content-disposition", "filename=pdf");
15                 Response.AddHeader("content-length", buffer.Length.ToString());
16                 Response.BinaryWrite(buffer);
17             }
18             catch (Exception exp)
19             {
20                 throw new Exception("错误", exp);
21             }
22             finally
23             {
24                 Response.Flush();
25                 Response.Close();
26                 Response.End();
27             }
28         }
View Code

相关文章:

  • 2022-12-23
  • 2021-11-25
  • 2021-11-16
  • 2022-02-19
  • 2021-05-04
  • 2022-12-23
  • 2021-09-12
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-02
相关资源
相似解决方案