下载pdf文件时会下载一个字节文件 [英] A byte file gets downloaded while downloading a pdf file

查看:92
本文介绍了下载pdf文件时会下载一个字节文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在将动态生成的pdf文件下载到服务器文件夹。但是它工作正常。但问题是,在下载pdf文件时,还会下载一个字节文件与pdf文件一起使用0kb。任何人都可以帮助我。任何人都会非常感激。



我的尝试:



Hi All,
I am downloading a dynamically generated pdf file to server folder.However it is working fine.But the problem is that while the pdf file is downloaded ,a byte file is also downloaded alongwith pdf file with 0kb. Can anyone help me please.Any hep will be really appreciated.

What I have tried:

pdfDoc.Add(pdfTable);
               pdfDoc.Close();
               string newfile = Name + "_" + DateTime.Now.ToString("dd-MMM-yyyy") + ".pdf";

               String path_name = "~/Sample/SampleReports/";
               var pdfPath = Path.Combine(Server.MapPath(path_name));

               string username = "Test";
               string password = "12345";
              //String file_name_pdf = "Test.pdf";

              var pdfContents = mStream.ToArray();
              File.WriteAllBytes(Path.Combine(pdfPath, newfile), pdfContents);
              WebRequest request = WebRequest.Create(Server.MapPath("~/Sample/SampleReports/" + pdfContents));
               request.Method = WebRequestMethods.Ftp.UploadFile;

               request.Credentials = new NetworkCredential(username, password);
               Stream reqStream = request.GetRequestStream();
               reqStream.Close();

推荐答案

您正在向路径追加一个字节数组:

You are appending a byte array to a path:
WebRequest request = WebRequest.Create(Server.MapPath("~/Sample/SampleReports/" + pdfContents));


这篇关于下载pdf文件时会下载一个字节文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆