我正在尝试使用Rotativa组件在Web服务器磁盘上永久存储(不显示)发票副本。两个问题:
感谢。
这是我的代码:
[HttpPost]
public ActionResult ValidationDone(FormCollection formCollection, int orderId, bool fromOrderDetails)
{
Order orderValidated = context.Orders.Single(no => no.orderID == orderId);
CommonUtils.SendInvoiceMail(orderValidated.customerID , orderValidated.orderID);
var filePath = Path.Combine(Server.MapPath("/Temp"), orderValidated.invoiceID + ".pdf");
var pdfResult = new ActionAsPdf("Index", new { name = orderValidated.invoiceID }) { FileName = filePath };
var binary = pdfResult.BuildPdf(ControllerContext);
FileContentResult fcr = File(binary, "application/pdf");
// how do I save 'fcr' on disk?
}
答案 0 :(得分:1)
你有可以直接保存到磁盘的字节数组:
var binary = pdfResult.BuildPdf(ControllerContext);
System.IO.File.WriteAllBytes(@"c:\foobar.pdf", binary);
答案 1 :(得分:0)
string FileName="YOUR FILE NAME";
//首先给文件命名
string Path=Server.MapPath("YourPath in solution"+Filename+".Pdf")
//提供您的路径和文件扩展名。两者都是必需的。
binary[]= YOUR DATA
//描述您要保存为文件的数据。
System.IO.File.WriteAllBytes(Path, binary);
这很简单......