這可能看起來像一個微不足道的問題,我想打開一個現有的pdf模板,編輯並壓扁文件,然後作爲電子郵件附件發送。但是,如何設置PdfReader來讀取位於我的Content文件夾(Content/Documents/PDFFile.pdf)中的文件。這是我給出的錯誤「(無論我嘗試的路徑).pdf找不到作爲文件或資源」。如何設置PdfReader文件路徑?
using (MemoryStream ms = new MemoryStream())
{
//Error is here...
PdfReader reader = new PdfReader("~/Content/Documents/PDFFile.pdf");
PdfStamper formFiller = new PdfStamper(reader, ms);
AcroFields formFields = formFiller.AcroFields;
formFields.SetField("Name", formData.Name);
formFields.SetField("Location", formData.Address);
formFields.SetField("Date", DateTime.Today.ToShortDateString());
formFields.SetField("Email", formData.Email);
formFiller.FormFlattening = true;
formFiller.Close();
MailMessage msg = new MailMessage();
msg.To.Add(new MailAddress("[email protected]"));
msg.From = new MailAddress("[email protected]");
msg.Subject = "Application Form";
msg.Body = "TEST";
msg.IsBodyHtml = true;
msg.Attachments.Add(new Attachment(ms, "Application.pdf", "application/x-pdf"));
SmtpClient client = new SmtpClient("10.1.1.15");
client.UseDefaultCredentials = true;
}
任何建議/想法/建議?
,如果你使用絕對路徑是否行得通?我還沒有嘗試,但我的第一個猜測是PDFReader沒有正確解釋'〜/'。 – Kendrick 2011-06-02 15:23:12
我使用了「../」,「../../」以及仍然沒有運氣 – MrM 2011-06-02 15:26:37
我正在考慮完整的本地路徑,包括驅動器號等。 – Kendrick 2011-06-02 15:31:27