<!--[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
- Create a new project
- Click
File->New->Project
- Select “Class Library”
- For name, type
“MyCustomRouter”
- For location, type “D:\Lab
Work”
- Click “Ok”
- Add the following references:
- Add a reference to
Microsoft.SharePoint.dll
- Add a reference to
Microsoft.Office.Policy.dll
Task 2 – Create the
router
- In your project, rename
Class1.cs to MyCustomRouter.cs
- Right click, select
“Rename”
- Click “yes” to rename
the class
- 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;
|
- Implement the IRouter interface:
|
public class MyCustomRouter : IRouter
|
- Right click the IRouter text,
select Implement Interface->Implement interface
- 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
- Right click the
MyCustomRouter project, select “Properties”
- Click the “Signing” tab
- Click the “Sign the assembly”
checkbox
- In the dropdown, select
“<new>…”
- For key file name, type
“MyCustomRouter”
- Uncheck the “Protect my key
file…”
- Click “Ok”
- Compile the project, press F6
- Drag the D:\Lab Work\ MyCustomRouter\MyCustomRouter
\bin\Debug\ MyCustomRouter.dll file to the GAC (C:\windows\assembly)
Task 4 – Create a
deployment application
- Create another project
- In Visual Studio,
click File->Add->New Project
- Select “Windows
Application”
- For name, type
“MyCustomRouterApp”
- For location, type “D:\Lab
Work”
- Add some references
- Add a reference to
Microsoft.SharePoint.dll
- Add a reference to
Microsoft.Office.Policy.dll
- Add a button called
“Register”, double click it
- Add the following using
statements:
|
using Microsoft.SharePoint;
using Microsoft.Office.RecordsManagement;
using Microsoft.Office.RecordsManagement.RecordsRepository;
using
Microsoft.Office.RecordsManagement.InformationPolicy;
|
- 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!");
|
- NOTE: Be sure to replace servername and public key token!
- Set the MyCustomRouterApp to
be the startup project
- Right click the
project, select “Set as startup project”
- Run the application, click
the “Register” button
Task 4 – Test the
newly deployed router
- Open your Record Center Site
(http://servername:107)
- Click “Record Routing”
- Edit the “Test” routing
record
- For Router, select “My
Router”
- Click “Ok”
- Open the RecordsManagementApp
project from the last lab, submit the file again!
- Open your c:\ drive folder
and notice the new file called “Custom Submit (no url)”, your new record
router is working!