Creating a Custom Router for the Records Center

<!–[if !mso]>

Module #03: Custom
Router Lab #
03

 

 

Course:           Programming
Microsoft Office SharePoint Server

Estimated Time to Complete:  30 minutes

Objectives:

·        
Create a Custom
Router

Operating
Notes:
 

 

·        
None


Deliverables:

·        
None

 

Overview:         Learn
to extend the use of the Records Center!

Exercise 1 – Create A Custom Router

Purpose:
        Create
a new record router to route submitted documents!

Result:           
A new custom router

Task 1 – Create a
Class Library

  1. Create a new project
    • Click
      File->New->Project
    • Select “Class Library”
    • For name, type
      “MyCustomRouter”
    • For location, type “D:Lab
      Work”
    • Click “Ok”
  2. Add the following references:
    • Add a reference to
      Microsoft.SharePoint.dll
    • Add a reference to
      Microsoft.Office.Policy.dll

Task 2 – Create the
router

  1. In your project, rename
    Class1.cs to MyCustomRouter.cs
    • Right click, select
      “Rename”
    • Click “yes” to rename
      the class
  2. Add the following using statements:


using System.IO;

using Microsoft.SharePoint;

using Microsoft.Office.RecordsManagement;

using
Microsoft.Office.RecordsManagement.RecordsRepository;

using
Microsoft.Office.RecordsManagement.PolicyFeatures;

using Microsoft.Office.RecordsManagement.InformationPolicy;

 

 

  1. Implement the IRouter interface:


public class MyCustomRouter : IRouter

 

  1. Right click the IRouter text,
    select Implement Interface->Implement interface
  2. Update the OnSubmitFile
    method to the following:


try

            {

               
//Save it to disk

               
File.Create("C:\" + sourceUrl).Write(fileToSubmit, 0,
fileToSubmit.Length);

            }

           
catch (Exception ex)

            {

               
return RouterResult.RejectFile;

            }

 

           
return RouterResult.SuccessContinueProcessing;

 

 

Task 3 –Strong name
the project

  1. Right click the
    MyCustomRouter project, select “Properties”
  2. Click the “Signing” tab
  3. Click the “Sign the assembly”
    checkbox
  4. In the dropdown, select
    “<new>…”
  5. For key file name, type
    “MyCustomRouter”
  6. Uncheck the “Protect my key
    file…”
  7. Click “Ok”
  8. Compile the project, press F6
  9. Drag the D:Lab Work MyCustomRouterMyCustomRouter
    inDebug MyCustomRouter.dll file to the GAC (C:windowsassembly)

Task 4 – Create a
deployment application

  1. Create another project
    • In Visual Studio,
      click File->Add->New Project
    • Select “Windows
      Application”
    • For name, type
      “MyCustomRouterApp”
    • For location, type “D:Lab
      Work”


    • Click “Ok”
  1. Add some references
    • Add a reference to
      Microsoft.SharePoint.dll
    • Add a reference to
      Microsoft.Office.Policy.dll
  2. Add a button called
    “Register”, double click it
  3. Add the following using
    statements:


using Microsoft.SharePoint;

using Microsoft.Office.RecordsManagement;

using Microsoft.Office.RecordsManagement.RecordsRepository;

using
Microsoft.Office.RecordsManagement.InformationPolicy;

 

  1. In the button event handler,
    add the following:


using(SPSite site = new SPSite("http://servername:107"))

{

           
SPWeb web = site.RootWeb;

           
RecordSeriesCollection series = new RecordSeriesCollection(web);

           
series.AddRouter("My Router", "MyCustomRouter,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=[YOURPUBLICKEYTOKEN]", "MyCustomRouter.MyCustomRouter");

}

 

MessageBox.Show("Done!");

  1. NOTE: Be sure to replace servername and public key token!
  2. Set the MyCustomRouterApp to
    be the startup project
    • Right click the
      project, select “Set as startup project”
  3. Run the application, click
    the “Register” button

Task 4 – Test the
newly deployed router

  1. Open your Record Center Site
    (http://servername:107)
  2. Click “Record Routing”
  3. Edit the “Test” routing
    record


  1. For Router, select “My
    Router”


  1. Click “Ok”
  2. Open the RecordsManagementApp
    project from the last lab, submit the file again!
  3. Open your c: drive folder
    and notice the new file called “Custom Submit (no url)”, your new record
    router is working!