What you want to see on DotNetFunda.com ?
Go to DotNetFunda.com
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 7698 |  Welcome, Guest!   Register  Login
Home > Articles > SharePoint > Routing the Files in SharePoint

Routing the Files in SharePoint

Article posted by Kollikr on 10/17/2012 | Views: 1530 | Category: SharePoint | Level: Advance | Points: 250 red flag


In the Document management space one of the requirements is routing the documents automatically into appropriate folders or subfolders inside a document library.
This article explains about the Out of box feature that is provided to meet the above requirement, the limitation of SharePoint 2010 and the Custom solution which meets the requirement

Introduction


In the Document management space one of the requirements is routing the documents automatically into appropriate folders or subfolders inside a document library.

This article explains about the Out of box feature that is provided to meet the above requirement, the limitation of SharePoint 2010 and the Custom solution which meets the requirement

OOTB SharePoint Option:

In SharePoint 2010 there is a feature called Content Organizer rule which addresses the above need through its attributes called Target location > Destination.

See those attributes in the below content organizer rule

 

 

Limitation with the content organizer rule routing


Whereas there is a limitation with these attributes in terms of creating hierarchical folders. For example if the requirement is to create multiple levels of folders/subfolders inside the target location based on the selected metadata it is not possible with the OOTB content organizer rule. It can only create one level below the target location.

How to achieve this functionality through Custom Router?


We can leverage Custom router to create the hierarchical folders and route the document appropriately to the corresponding folder.

Custom router is the custom class library that implements ICustomRouter interface and this interface has one method called OnSubmitFil which needs to be implemented by the custom router’s class.

Implementing Custom router:

Routing can be customized by implementing an Interface called “ICustomRouter” which has only one method named “OnSubmitFile”. This code will be called by Content Organizer internally.

Here is the signature of OnSubmitFile

CustomRouterResult OnSubmitFile(

         EcmDocumentRoutingWeb contentOrganizerWeb,

         string recordSeries,

         string userName,

         Stream fileContent,

         RecordsRepositoryProperty[] properties,

         SPFolder finalFolder,

         ref string resultDetails

)

Please refer http://msdn.microsoft.com/en-us/library/ee561223 for more details on this interface.

Perform the below steps to implement this method to meet our requirement.

1.       Retrieve the properties from the parameter called properties.

2.       Push all the values into a Hashtable

3.       Read the required properties based on which we need to create the hierarchical folder structure.

4.       See whether this folder structure already exists.

5.       Create the folder structure if it does not exist.

6.       Move the file into the folder.

See the sample code below

public class MyCustomRouter : ICustomRouter

    {

       

      CustomRouterResult ICustomRouter.OnSubmitFile(

                EcmDocumentRoutingWeb contentOrganizerWeb,

                string recordSeries, // Content type name

                string userName,

                Stream fileContent,

                Microsoft.SharePoint.RecordsRepositoryProperty[] properties,

                SPFolder finalFolder,

                ref string resultDetails)

        {

         

          

 

  string fileContentString = string.Empty;

  StreamReader sr = new StreamReader(fileContent);

  {

    fileContentString = sr.ReadToEnd();

  }

  using (SPSite site = new SPSite(contentOrganizerWeb.DropOffZoneUrl))

    {

        SPWeb web = site.OpenWeb();

        // User creating the file

      

        // Create a Hashtable of properties which forms the metadata for the file

        Hashtable fileProperties = EcmDocumentRouter.GetHashtableForRecordsReposi       toryProperties(properties, recordSeries);

       

 

 

EcmDocumentRouter.SaveFileToFinalLocation(contentOrganizerWeb,

    finalFolder,

    finalStm,

    fileName,

    "",

    fileProperties,

    submittingUser,

    true /*override versioning settings on the content organizer and create a new file*/, "");

        }

 

        resultDetails = "File was inspected and sensitive data was found. File has been saved with a custom name.";

        return CustomRouterResult.SuccessCancelFurtherProcessing;

    }

}

        }

    }

 

Now the custom router is ready to use. How this router will be attached to the Content Organizer?

Attaching Custom router to the Content Organizer rule:

The custom code mentioned in the above section need to compile into an assembly and sign the assembly with the key. Now the assembly is ready to add into the GAC where SharePoint is running.

Add the assembly into GAC and it is ready to use inside the SharePoint.

Modify the Content Organizer rule:

Go to the Content Organizer rule to which we want to attach the custom router. Edit properties and go to Custom router field and select our newly created Custom router assembly over there.


Click on OK will save the Content Organizer rule and Custom router will route the incoming documents based on the logic written in Custom Router

Co.nclusion

This article explains the power of Custom router and how can you route the files automatically based on the property values.

Reference

http://msdn.microsoft.com/en-us/library/ee561223

If you like this article, subscribe to our RSS Feed. You can also subscribe via email to our Interview Questions, Codes and Forums section.

Page copy protected against web site content infringement by Copyscape
Found interesting? Add this to:



Please Sign In to vote for this post.

Latest Articles from Kollikr

About Kiran Kolli

Experience:12 year(s)
Home page:http://www.dotnetfunda.com
Member since:Friday, November 11, 2011
Level:Starter
Status: [Member]
Biography:Having 12 years of experience in Architecture,Deisgn and development of enterprise applications using Microsoft technologies
>> Write Response - Respond to this post and get points
Related Posts

In this article we will be seeing how to create Scopes in SharePoint 2010 Enterprise Search Service Application using PowerShell

In the previous session of SharePoint article we had discussed about the basics of SharePoint. In this session we will:- • create site / site collection • Understand the ready made functional reusable modules • Learn how we can display a simple page and later apply master pages of SharePoint. • Host a Inline code and behind code page in SharePoint • Understand the concept of features and understand step by step how to enable / disable a feature • How do display a feature in Admin

In this article we will be seeing how to create an InfoPath web part in SharePoint 2010.

In this article I will explain how to install SharePoint 2010.

In sharepoint view if the view name is bit long then its trimming the name with three dots. Last week I got a requirement from client that he need a fullname of the view.So I searched to see any configuration change in sharepoint. But I didnt come across any solution. So i plan to do it using javascript......

More ...
About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/26/2013 4:39:37 AM