Filed under: SharePoint 2010

Custom Event Receiver

I was faced with the challenge of writing a proof of concept today. The scenario was the following:

Client is using SharePoint 2010 as a EDRMS
Client will be performing bulk scanning of historic paper based records into the EDRMS
Client is using third party software, to add necessary meta data to items scanned into the system, this software uses OCR and coversheets.
Documents scanned will be automatically added to document library; then based on document meta data, the file should be automatically moved to a folder contained in another document library.
If the folder mentioned above does not currently exist, it should be created based on the meta data of the document.
The folder mentioned above, also contains subfolders, which will also need to be generated.

The first major hurdle I had to overcome was the fact that while writing the proof of concept, the documents I would be dealing with while developing would have no meta data. The would be sample documents that I would upload from my development machine. I pondered on this for a while, how could I uniquely name the generated folder which would be automatically generated (if it doesn't already exist) when a new document is added to the library. I decided for testing purposes, I would generate the folder based upon the current date and time, later when a UAT environment is setup, I can refine the process and add the meta data consumption which is required.

The basic flow of the project is shown below (please forgive my terrible Visio skills):

File_plan_flow

Because in the final solution I will be dealing with custom content types, I decided that I would use a customized event receiver on the document library which scanned files were routed to, rather than the Content Organizer.

My code is shown below (minus error checking and sanity checking which I have omitted for the sake of clarity), I hope that it helps someone else in a similar situation, and if not, then should I ever be faced with a similar situation in the future, I know where I can find it.

If you find this useful or have any comments, let me know below.