Search code examples
c#sharepointsharepoint-2007sharepoint-workflowworkflow-activity

Change file extension SPListItem SharePoint 2007


I've Forms Library in SharePoint 2007. I've created a custom workflow activity that makes it possible to convert InfoPath documents to PDF. But when I try to replace original InfoPath file to the new PDF file it keeps referencing to the InfoPath file. How can I rename the InfoPath list item to PDF?

It can't be changed manually (it's a requirement to be automatically). My only problem now is that I need to store the PDF file in the same SPListItem. Because I want to keep the metadata and history information of the file (requirement).

My code:

//new url = file.pdf
//old url = file.xml
//pdf doc = byte[] of pdf file

file.MoveTo(newUrl);
file.ReplaceLink(oldUrl, newUrl);
file.SaveBinary(pdfdoc);

file.Update();
file.CheckIn("File Converted to PDF - V1.0");
file.Update();

Solution

  • Fixed it by creating a new SPListItem for the PDF file. Then after that I copy the content of every field to the new SPListItem. And after that you can delete the old file or archive it for later use.