[英]Save PDF stream into folder
I am creating a Stream, I am able to download it as a PDF file & also able to return it as a Filestream into PDF format. 我正在创建一个Stream,我可以将其下载为PDF文件,也可以将其作为Filestream返回为PDF格式。
But I want to save this stream into a folder into PDF file format. 但我想将此流保存为PDF文件格式的文件夹。
I am using some code to create stream as:: 我正在使用一些代码来创建流:
public void PrintInvoice(long ID)
{
ReportDocument rd = new ReportDocument();
rd.Load(AppDomain.CurrentDomain.BaseDirectory+(@"\Reports\InvoiceDocument.rpt"));
Stream stream = rd.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
stream.Seek(0, SeekOrigin.Begin);
return File(stream, "application/pdf", "TestCrystal.pdf");
}
How can I save the formed stream into Folder into PDF file format? 如何将形成的流保存到PDF格式的Folder中? I want to save the PDF file on Client Machine. 我想将PDF文件保存在客户端计算机上。
To save file on Server - 要将文件保存在服务器上-
using (MemoryStream ms = new MemoryStream())
{
stream.CopyTo(ms);
System.IO.File.WriteAllBytes(Server.MapPath("~/Report1.pdf"), ms.ToArray());
}
To save file on Client - 要将文件保存在客户端上-
Option1 - Using ActiveX, you Save file on Client machine without user interaction 选项1- 使用ActiveX,无需用户交互即可将文件保存在客户端计算机上
Option2 - Using Silverlight, you can put the file in IsolatedStorage available on client machine 选项2- 使用Silverlight,您可以将文件放入客户端计算机上可用的IsolatedStorage中
Unfortunately you cannot save file with JQuery/JavaScript, due to security issues. 不幸的是,由于安全问题,您无法使用JQuery / JavaScript保存文件。 And there are many other options like Java Applets etc. 并且还有许多其他选项,例如Java Applets等。
I do not understand the reason why do you want to save file on client machine from server side. 我不明白为什么要从服务器端在客户端计算机上保存文件的原因。 Let user take that responsibility, I mean let user click a link and get the file from server and save it in the location of his interest. 让用户承担此责任,我的意思是让用户单击链接并从服务器获取文件并将其保存在他感兴趣的位置。 Don't you think it is security issue if server tries to save/access files on client machines. 如果服务器尝试在客户端计算机上保存/访问文件,您不认为这是安全问题。 So I would suggest you to re-think your implementation and come up with different workflow. 因此,我建议您重新考虑您的实现并提出不同的工作流程。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.