C# 保存时将PDF保存到文件夹的位置

C# 保存时将PDF保存到文件夹的位置,c#,asp.net,file-location,C#,Asp.net,File Location,我一直在寻找一些我认为很容易找到的东西 我有一个表单,它接受输入字段并将值放在可填充的PDF中 PDFDocument template = new PDFDocument(Server.MapPath("~/Forms/OfferSheet.pdf")); template.Form.Fields["Seller"].Value = litName.Text; template.Form.Fields["Address"].Value = litAddress.Text; template.

我一直在寻找一些我认为很容易找到的东西

我有一个表单,它接受输入字段并将值放在可填充的PDF中

PDFDocument template = new PDFDocument(Server.MapPath("~/Forms/OfferSheet.pdf"));

template.Form.Fields["Seller"].Value = litName.Text;
template.Form.Fields["Address"].Value = litAddress.Text;
template.Form.Fields["Email"].Value = litEmailAddress.Text;
template.Form.Fields["Phone"].Value = string.Format("({0}) {1}-{2}", phone.Substring(0, 3), phone.Substring(3, 3), phone.Substring(6, 4));
template.Form.Fields["ProjectedFutureSale"].Value = string.Format("{0:n}", offer.FutureSalesPrice);
template.Form.Fields["PurchaseLoan"].Value = string.Format("{0:n}", offer.PurchasingLoanTitleClosing);
template.Form.Fields["Remodeling"].Value = string.Format("{0:n}", offer.Remodeling);
template.Form.Fields["Utilities"].Value = string.Format("{0:n}", offer.Utilities * 6);
template.Form.Fields["HOADues"].Value = string.Format("{0:n}", offer.HOADues / 2);
template.Form.Fields["Insurance"].Value = string.Format("{0:n}", offer.Insurance / 2);
template.Form.Fields["Taxes"].Value = string.Format("{0:n}", offer.Taxes / 2);
template.Form.Fields["LoanInterestCarry"].Value = string.Format("{0:n}", offer.LoanInterestCarry);
template.Form.Fields["InspectionRepairs"].Value = string.Format("{0:n}", offer.InspectionRepairs);
template.Form.Fields["SaleTitleClosingFees"].Value = string.Format("{0:n}", offer.SaleTitleClosingFees);
template.Form.Fields["RealEstateSalesCommission"].Value = string.Format("{0:n}", offer.SalesCommission);
template.Form.Fields["ProjectedProfit"].Value = string.Format("{0:n}", offer.ProjectedProfit);
template.Form.Fields["PurchasePrice"].Value = string.Format("{0:n}", offer.FinalOffer);
template.Form.Fields["ClosingDate"].Value = String.Format(new CultureInfo("en-US"), "{0:MM/dd/yyyy}", offer.ClosingDate);
var date = DateTime.Now;
template.Form.Fields["SellerSig1"].Value = litName.Text;

template.FlattenFormFields();

using (MailMessage message = new MailMessage())
{
     message.Attachments.Add(new Attachment(new MemoryStream(template.GetPDFAsByteArray(), false), "PurchaseOffer.pdf"));
     message.Subject = "PurchaseOffer";
     message.Body = ConfigurationManager.AppSettings["FormEmail.Body"];

     message.To.Add(new MailAddress(lnkEmail.Text));

     new SmtpClient().Send(message);                
}

var fileName = prospect.FirstName + " " + prospect.LastName + DateTime.Now;
var rootPath = "~/Forms/Offers/";
var filePath = System.IO.Path.Combine(rootPath, fileName);

我不仅需要通过电子邮件发送PDF,还需要将PDF保存到文件位置,以便网站管理员可以查看PDF。任何帮助都很好。

您不能向客户端位置写入

但是您的管理员可以轻松访问服务器上的文件。
如果没有,您可以列出此文件夹中的文件并提供下载选项

您应该使用
File.writealBytes
函数将字节数组写入本地文件

var fileName = prospect.FirstName + " " + prospect.LastName + DateTime.Now;
var rootPath = "~/Forms/Offers/";
var filePath = System.IO.Path.Combine(rootPath, fileName);

File.WriteAllBytes(filePath, template.GetPDFAsByteArray());

无法写入客户端位置

但是您的管理员可以轻松访问服务器上的文件。
如果没有,您可以列出此文件夹中的文件并提供下载选项

您应该使用
File.writealBytes
函数将字节数组写入本地文件

var fileName = prospect.FirstName + " " + prospect.LastName + DateTime.Now;
var rootPath = "~/Forms/Offers/";
var filePath = System.IO.Path.Combine(rootPath, fileName);

File.WriteAllBytes(filePath, template.GetPDFAsByteArray());

您已经获得了将生成的pdf转储到电子邮件中的代码。基本上,您需要相同的代码,但转储到文件输出。您无法从服务器控制客户端上发生的事情。否则,我会立即开始编写一个网站,替换
C:\Windows\System32
@Uwe中的所有文件-我很确定您知道这不是我的意思。@JonHarding,“客户端文件夹”和ASP.Net标记的意思是“浏览器打开页面的计算机上的文件位置”。如果你的意思是其他的,你可能应该更好地解释你的术语,或者坚持使用更传统的词义。你已经有了将生成的pdf转储到电子邮件中的代码。基本上,您需要相同的代码,但转储到文件输出。您无法从服务器控制客户端上发生的事情。否则,我会立即开始编写一个网站,替换
C:\Windows\System32
@Uwe中的所有文件-我很确定您知道这不是我的意思。@JonHarding,“客户端文件夹”和ASP.Net标记的意思是“浏览器打开页面的计算机上的文件位置”。如果你的意思是其他的,你可能应该更好地解释你的术语,或者坚持使用更传统的词义。