I have a read/copy/write process that access a folder that is installed with the software.
This worked great when testing the build, but once the solution was created it completely stopped working. What am I doing wrong?
(breakdown of code) I essentially access a PDF called CTW.pdf Next we create a temp copy which the software fills in and flatted On completion, the software saves the new copy to the same directory with a new name (i simply add the time and date to the file name)
Here's the code:
if (screenLock.Text == "")
{
}
else
{
string fileNameExisting = @"C:\Program Files (x86)\Compliance Pro 2\CTW.pdf";
string fileNameNew = @"C:\Program Files (x86)\Compliance Pro 2" + " CTW.pdf" + DateTime.Now.ToString("M/d/yyyy") + DateTime.Now.ToString("hh:mm:ss");
using (var existingFileStream = new FileStream(fileNameExisting, FileMode.Open))
using (var newFileStream = new FileStream(fileNameNew, FileMode.Create))
{
// https://www.codeproject.com/Tips/679606/Filling-PDF-Form-using-iText-PDF-Library
// Open existing PDF
var pdfReader = new PdfReader(existingFileStream);
// PdfStamper, which will create
var stamper = new PdfStamper(pdfReader, newFileStream);
var form = stamper.AcroFields;
var fieldKeys = form.Fields.Keys;
foreach (string fieldKey in fieldKeys)
{
form.SetField(fieldKey, "");
}
stamper.AcroFields.SetField("OSJNonOSJ", "TFSN");
stamper.AcroFields.SetField("Branch", "9DCF");
stamper.AcroFields.SetField("User Name Last First", "Joe" + "Pearson");
stamper.AcroFields.SetField("Tested by Last First", emailTo.Text);
stamper.AcroFields.SetField("Date Tested", DateTime.Now.ToString("M/d/yyyy"));
stamper.AcroFields.SetField("COMMENTS", notes.Text);
stamper.AcroFields.SetField("WDE-Yes", user.Text + "5");
}
}
NOTE: I have worked really hard to ensure my software does not require ANY administrative access to complete it's functions, I would really like to avoid that here as well.