Tue May 16, 2017 3:48 pm
Hi
I found a solution using the current version.
Once I realized that the portfolio file was using attachments, the solution was fairly simple.
I'm posting the code in case anyone else has the same issue:
private void btnOpenPDFs_Click(object sender, EventArgs e)
{
foreach (DataGridViewRow grdRowPDF in grdPDFprops.SelectedRows)
{
try
{
//Select the files I want to process from a data grid
//The data in the grid is filtered by the contects of the filename (*.pdf)
DataGridViewRow selectedRowPDF = grdPDFprops.Rows[grdRowPDF.Index];
//I'm working off a database but it would be just as simple to work of a directory listing
string strFile = Convert.ToString(selectedRowPDF.Cells["FileName"].Value);
string strExt = Convert.ToString(selectedRowPDF.Cells["Extention"].Value);
string strPath = Convert.ToString(selectedRowPDF.Cells["Path"].Value);
//location to store the original portfolio file once processed
string strDestPath = strPath + @"Portfolios\";
//Open the pdf and determine if it has attachments
PdfDocument docPDF = new PdfDocument();
docPDF.LoadFromFile(strPath + strFile);
PdfAttachmentCollection docPDFAttached = docPDF.Attachments;
PdfAttachment docAttach = null;
//If attachments extract them to the same directory as the portfolio was stored
if (docPDF.Attachments.Count > 0)
{
selectedRowPDF.Cells["Portfolio"].Value = docPDF.Attachments.Count;
foreach (PdfAttachment pdfDoc in docPDF.Attachments)
{
string strFileAttachment = pdfDoc.FileName;
docAttach = pdfDoc;
if (docAttach != null)
{
File.WriteAllBytes(strPath + docAttach.FileName, docAttach.Data);
}
}
}
docPDF.Close();
//move the portfolio and update my database and the grid
System.IO.File.Move(strPath + strFile, strDestPath + strFile);
UpdateScannedFiles(strFile, Convert.ToInt16(selectedRowPDF.Cells["Portfolio"].Value));
selectedRowPDF.Cells["Inspected"].Value = true;
grdPDFprops.Refresh();
}
catch (Exception exPDF)
{
string strStatus = exPDF.ToString();
}
}
MessageBox.Show ("Done");
}
Thanks,
Rob