Customizing Sitecore Upload Pipeline for both folder and database based Media

I wanted to upload documents to Sitecore Media library and at the time of upload, I would like to replace the metadata on the pdf file.

Many of you probably have looked at this document for reference from Sitecore SDN.

But that document has few problems. I will point those out as I write this document.

First part was to find a suitable pdf tool that will let me modify the pdf. I found both PdfNet and iTextSharp works great for my goal. They are open source and free to use and have great supporting community.

Second, I  have to update the Web.Config. But I didn’t want to it like that. I like the way you can patch the Sitecore config files. So I wanted to use that approach. This way it is much more modular and easier to change and I don’t have to touch the main web.config (kind of).

Third, I will create a class that will override the process for Pipeline.

You should ask yourself, where I am saving my files? Is it in the Database? or is it in the file system?

Because you will have to handle it differently depending on how you are saving your file.

The way save works, it will look for the location you are saving it. Database or file system.

Then it will proceed to save it in the right location.

So if you are saving it in file system, you can do the following

  1. Create the class to create the class that will have the Process method that takes the UploadArgs as argument. Use this link
  2. Create the patch file to execute before save. This has to be the proper location.
<configuration xmlns:patch="">
     <uiUpload name="[Your custom class namespace], [project namespace]" patch:before="processor[@type='Sitecore.Pipelines.Upload.Done, Sitecore.Kernel]">
     </uiUpload > 

3. Create your PDF read and update code in a class. You can use this link Here.

If you are saving it in the Database

  1. You have to create a custom class that will replace the Save method of the Sitecore pipeline. Go ahead and use the Resharper dotpeek or the build in tool in Visual Studio to look in the save class. **Sitecore.Pipelines.Upload.Save
  2. Locate where the file is calling .Upload() (Line 63) , you have to swap the File property in the MediaUploader object. In line 49, immediately after the else statement, create your file and swap it for file1 in line 52.
  3. Create your patch file to be called before Done in uiUpload segment in Web.Config.
  4. Comment out the Save on uiUpload segment.

If you need help with Databaseone, I will continue writing here.  But the strategy is defined here.