I am getting System.IO.FileNotFoundException when referencing the dll from a SharePoint 2013 Event Receiver: Could not load file or assembly 'Aspose.Pdf, Version=10.2.0.0, Culture=neutral, PublicKeyToken=6947866647e416ec' or one of its dependencies. The system cannot find the file specified.
Please let me know what additional information you need to assist with this issue.
Here is the code:
public class PDFUpdaterTestReceiver : SPItemEventReceiver
{
/// <summary>
/// An item was added.
/// </summary>
public override void ItemAdded(SPItemEventProperties properties)
{
base.ItemAdded(properties);
if (properties.ListTitle == "Documents")
{
SPSecurity.RunWithElevatedPrivileges(delegate
{
using (SPSite site = new SPSite(properties.WebUrl))
{
using (SPWeb web = site.OpenWeb())
{
try
{
//get list item
SPList list = web.Lists[properties.ListId];
SPListItem item = list.Items[properties.ListItem.UniqueId];
SPFile file = item.File;
MemoryStream myStream = new MemoryStream();
byte[] bf = file.OpenBinary();
MemoryStream ms = new MemoryStream(bf);
//Aspose PDF Classes - get and modify document links
Document document = new Document(ms);
foreach (Aspose.Pdf.Page page in document.Pages)
{
//get links for the current page
AnnotationSelector selector = new AnnotationSelector(new LinkAnnotation(page, Aspose.Pdf.Rectangle.Trivial));
page.Accept(selector);
IList linksList = selector.Selected;
//loop through links and update as needed
foreach (LinkAnnotation link in linksList)
{
string linkURI = (link.Action as Aspose.Pdf.InteractiveFeatures.GoToURIAction).URI;
if (linkURI.Contains("intranet.chop.edu"))
{
//need to update GoToURIAction
link.Action = new Aspose.Pdf.InteractiveFeatures.GoToURIAction(linkURI + "?CHOP=atchop");
//GoToRemoteAction goToR = (GoToRemoteAction)link.Action;
// Next line update destination, do not update file
//goToR.Destination = new XYZExplicitDestination(document, 2, 0, 0, 1.5);
// Next line update file
//goToR.File = new FileSpecification("c:/pdftest/PDFInput (1).pdf");
}
}
}
//save document with updated links
//document.Save("c:/pdftest/ResultantFile.pdf");
document.Save(ms);
//update the list item
string linkFilename = file.Item["LinkFilename"] as string;
file.ParentFolder.Files.Add(linkFilename, ms, true);
}
catch (Exception ex)
{
properties.Status = SPEventReceiverStatus.CancelWithError;
properties.ErrorMessage = "Error : " + ex.Message;
}
}
}
});
}
}
}
Thanks.