Sample custom router for Records Center in SharePoint

Search

Accessible SharePoint WebSites
Download ARF

Sample custom router for Records Center in SharePoint

http://blog.thekid.me.uk

This is the third post in a series of posts about the Records Center in MOSS. (Part One, Part Two)

Creating a custom router is relatively straight forward in MOSS...All you need to do is create a class which implements the IRouter interface and register the router with the records center.

The IRouter interface has only one method called OnSubmitFile.

class CustomRouting : IRouter {

    public RouterResult OnSubmitFile(string recordSeries, string sourceUrl,

                                     string userName, ref byte[] fileToSubmit,

                                     ref RecordsRepositoryProperty[] properties,                          

                                     ref SPList destination,

                                     ref string resultDetails)    {       

 

return RouterResult.SuccessContinueProcessing;    }}

The return value from this method is a choice between

RouterResult.SuccessContinueProcessing – The routing succeeded continue with the default processing. The normal processing continues. Use this if you wish to add/modify some properties or modify the document.RouterResult.RejectFile – Reject the file becuase it is invalid for some reason. You can set the resultDetails argument to inform the user of the problem.

RouterResult.SuccessCancelFurtherProcessing – The processing has succeeded and do not perform the normal processing. Use this if you actually store the document yourself.

The documentation appears to imply that by changing the destination paramter you can change the ultimate destination of the routing. In my experience this does not actually occur unless there is a problem storing the document in the original document library. If this happens it does get routed to the destination you specify, but it does not copy the metadata. I am not sure if this is a bug, or by design though.

However, you can use SuccessCancelFurtherProcessing and store your document in the location of your choice. This is what the sample will demonstrate.

The sample code below shows a custom router which will route records based on their content type to folders in the document library specified by the routing table entry. The customer router creates a folder using the same name as the content type and then stores documents in folders based on the date.


The class implements the IRouter interface and the OnSubmitFile method.


public
RouterResult OnSubmitFile(string recordSeries, string sourceUrl,

                                string userName, ref byte[] fileToSubmit,

                                ref RecordsRepositoryProperty[] properties,

                                ref Microsoft.SharePoint.SPList destination,

                                ref string resultDetails)

{

    try

    {

        string sContentType = GetContentType(properties);

 

        if (string.IsNullOrEmpty(sContentType))

        {

            // Log the fact we didn't find it...but let the default processing continue

            Trace.WriteLine("RecordsRouting Failed...ContentType not found");

            return RouterResult.SuccessContinueProcessing;

        }

 

        HandleContentType(sContentType, sourceUrl, fileToSubmit, properties, destination);

 

        return RouterResult.SuccessCancelFurtherProcessing;

    }

    catch (Exception ex)

    {

        resultDetails = "Failed to route record: " + ex.Message;

        Trace.WriteLine(resultDetails);

        return RouterResult.RejectFile;

    }

}


The method attempts to get the ContentType from the file (this maybe missing if it was submitted from outside of SharePoint) and then calls HandleContentType.

HandleContentType does all the work of getting the new desination folder, creating the new filename, storing the document and copying the metadata.


private
void HandleContentType(string contentType, string sourceUrl,

                               byte[] fileToSubmit,

                               RecordsRepositoryProperty[] properties,

                               SPList destination)

{

    // Create a new filename using the date & time

    string sFileName = Path.GetFileNameWithoutExtension(sourceUrl) + " (" + DateTime.Now.ToUniversalTime().ToString("yyMMddHHmmss") + ")" + Path.GetExtension(sourceUrl);

 

    SPFolder oFolder = GetDestinationFolder(contentType, destination);

 

    // Add the document

    SPFile oFile = oFolder.Files.Add(sFileName, fileToSubmit);

    SPListItem oItem = oFile.Item;

 

    oItem["ContentTypeId"] = destination.ContentTypes[contentType].Id;

    oItem.Update();

 

    foreach (RecordsRepositoryProperty p in properties)

    {

        if (oItem.Fields.ContainsField(p.Name))

        {

            try

            {

                if (OkToCopyField(p.Name, oItem))

                    oItem[p.Name] = p.Value;

            }

            catch (Exception ex)

            {

                Trace.WriteLine(string.Format("Failed to copy field '{0}': {1}", p.Name, ex.Message));

            }

        }

    }

 

    oItem.Update();

}


There is also another class included in the project, FeatureReceiver. This class handles registering the router when the feature is activated and removing it again when it is deactivated. In order to make the custom router available you need to add the router to the RecordSeriesCollection of the Records Center site and so the feature should be activated within that site.


public
class FeatureReceiver : SPFeatureReceiver

{

    public override void FeatureActivated(SPFeatureReceiverProperties properties)

    {

        SPWeb oWeb = (SPWeb)properties.Feature.Parent;

        RecordSeriesCollection oSeries = new RecordSeriesCollection(oWeb);

        oSeries.AddRouter("TheKid Sample Router", "TheKid.RecordsCenter, Version=1.0.0.0, Culture=neutral, PublicKeyToken=0a0c37d47e875d49", "TheKid.RecordsCenter.RecordsRouting");

    }

 

    public override void FeatureDeactivating(SPFeatureReceiverProperties properties)

    {

        SPWeb oWeb = (SPWeb)properties.Feature.Parent;

        RecordSeriesCollection oSeries = new RecordSeriesCollection(oWeb);

        oSeries.RemoveRouter("TheKid Sample Router");

    }

 

    public override void FeatureInstalled(SPFeatureReceiverProperties properties)

    {}

 

    public override void FeatureUninstalling(SPFeatureReceiverProperties properties)

    {}

}


There are two downloads for this sample, one being the project with the code and the other being a WSP solution for you to deploy and try out the sample.

Download the Sample Project
Download the Sample WSP Solution

To install the wsp you will need to run the following command (I did try using the installer, but I couldn't get it to work for this solution).

stsadm -o addsolution -filename c:\thekid.recordscenter.wsp
stsadm -o deploysolution -name thekid.recordscenter.wsp -immediate -allowGacDeployment

You will then need to activate the sample in the 'Site Features' for the records center site.


Once it has been activated the router will be available to all routing entries. To try the router you can simply add it to the default unclassified routing entry. Edit the entry and change the Router entry at the bottom of the settings. If you cannot see this then the feature is either not activated for the records center or the activation failed in some way.

Press OK and now all new unclassified documents wil get routed using the new sample router.

This is just a sample and is not really production quality, but it should give you a good start in creating your own routers and getting the records center to store documents where you want them. You can lso read the records management Q&A here and more about records management here

Posted by Vincent Rothwell on Sunday, 15 Apr 2007 13:00  - 83 Comments
Orininally printed from http://thekid.me.uk - Copyright Vincent Rothwell 2007
 

Comments

Sunday, 27 Jul 2008 10:36 by Jason
Is there a way to inject an XSL into the 'properties' xml file that is created when a document is added to the record center?

Sunday, 27 Jul 2008 10:36 by Mike
When I build solution I receive a few errors. How could I fix this? I have added the two reference's Microsoft.Office.Policy and Microsoft.SharePoint. Thanks Errors: Error 1 The type or namespace name 'SPFeatureReceiver' could not be found (are you missing a using directive or an assembly reference?) Error 2 The type or namespace name 'SPFeatureReceiverProperties' could not be found (are you missing a using directive or an assembly reference?) Error 3 The type or namespace name 'SPFeatureReceiverProperties' could not be found (are you missing a using directive or an assembly reference?) and so on..

Sunday, 27 Jul 2008 10:36 by Mike
When I build solution I receive a few errors. How could I fix this? I have added the two reference's Microsoft.Office.Policy and Microsoft.SharePoint. Thanks Errors: Error 1 The type or namespace name 'SPFeatureReceiver' could not be found (are you missing a using directive or an assembly reference?) Error 2 The type or namespace name 'SPFeatureReceiverProperties' could not be found (are you missing a using directive or an assembly reference?) Error 3 The type or namespace name 'SPFeatureReceiverProperties' could not be found (are you missing a using directive or an assembly reference?) and so on..

Sunday, 27 Jul 2008 10:36 by Vince
Mike, Are you building it on a machine with SharePoint installed? You need to add a reference to Microsoft.SharePoint.DLL, if it is not on your machine you will need to copy it from your server. --Vince

Sunday, 27 Jul 2008 10:36 by Mike
Ok I got past the previous errors when building the solution. I was using the wrong version of Microsoft.SharePoint dll. Now one more problem. When sending a record over I receive the following error: The Archive & Delete Records Center refused the submission. Failed to route record: Object reference not set to an instance of an object. But it is still submitted to the record center. How do I not display this message?

Sunday, 27 Jul 2008 10:36 by Vince
Mike, You will have attach a debugger to it to see what the problem is. You may see more using DebugView and System.Diagnostics.Trace with out having to use the debugger. --Vince

Sunday, 27 Jul 2008 10:36 by Mike
Thank you Vince. The object reference not set to an instance of object error only appears when sending PDFs to the record center. I will try to run a debug on it--never done it before. I wish I knew visual studio to work with your code. I want to be able to create folder structure of the relative path. For example: Site Title/Document Library/Month 2008/the file.doc . Instead of creating document library/Month 2008/the file.doc Any suggestons? Thanks

Sunday, 27 Jul 2008 10:36 by Mike
Thank you Vince. The object reference not set to an instance of object error only appears when sending PDFs to the record center. I will try to run a debug on it--never done it before. I wish I knew visual studio to work with your code. I want to be able to create folder structure of the relative path. For example: Site Title/Document Library/Month 2008/the file.doc . Instead of creating document library/Month 2008/the file.doc Any suggestons? Thanks

Sunday, 27 Jul 2008 10:36 by Asif Ahmad
I followed your steps, but on my own record center I am having an error. When I go and click on "site features" under site settings I get this error: "Required attribute 'Scope' is missing from tag 'Elements' in feature definition for feature with ID '00000000-0000-0000-0000-000000000000'." I was going to see if you have possibly seen it before and maybe knew how to correct it. I tried googling the issue, but I could not find much information. Any assistance you could provide would be greatly appreciated. --A4orce84

Sunday, 27 Jul 2008 10:36 by Amit
Hi I tried your code. Have done everything fine, the feature is deployed on record center but still its not working. Even I tried it with the wsp provided by you, still the custom router is not working. Moreover I am not able to debug it. Any pointers regarding this would be really helpful. Thanks

Sunday, 27 Jul 2008 10:36 by Amit
Hi I tried your code. Have done everything fine, the feature is deployed on record center but still its not working. Even I tried it with the wsp provided by you, still the custom router is not working. Moreover I am not able to debug it. Any pointers regarding this would be really helpful. Thanks

Sunday, 27 Jul 2008 10:36 by Mike
Amit - Make sure you go in the record and from the drop down select the router. Also try to restart IIS. Instead of using content types for folders, I would like this router to use the asolute path for the folder stucture. For example if the site is http://domain.com/thekid/help/customrouter.doc i would like the custom router to create a directory structure of domain.com/thekid/help/customrouter.doc. Any advice would be greatly appreciated on how to accomplish this!

Sunday, 27 Jul 2008 10:37 by Michael
Hi Vince. I love the code you provided but I wish I was able to use it for my needs. I do not know anything about programming so hopefully you can provide me with some helpful information. Instead of putting the documents using folders by content types I would like create folders based on the relative path as to where the file came from. If the file hi.doc is in http://site.com/site/subsite/blog/, I would like the custom router you created create a folder structure in the record center site/subsite/blog I would think this would just be a few more lines of code but I don't. Please help? Thanks

Sunday, 27 Jul 2008 10:37 by Andy Burns
Looks like your problem is in the feature definition file - there is a good chapter about this in Bill English's book (Chapter 26, I believe). When creating a feature you have to give it a scope, which is apparently missing. Also, it needs a GUID, which it looks like yours doesn't have. Try looking up 'Creating custom features'

Sunday, 27 Jul 2008 10:37 by charles Gagnon
Hello ! I've made my own custom router and its working fine. The only missing part is the Audit of the source file. How can I find it via code ? I don't want to get the SPFile from the source then get the audit from there. I assume that there's a better way to do that. Thanks

Sunday, 27 Jul 2008 10:37 by Henry
I don't know what to say...I meticulously followed your steps and reviewd the code. I deployed this in a virtual environment ...everything went into place properly took a good portion of the day ..but I do not get any routing!!! After I send the content type...say agenda.doc(content type agenda)to a document repository meeting ...it ends up in the unclassified record...this is the second day and I reviewed everything....don't know what to say...except any thoughts...???? Thanks so much for your time, Henry

Sunday, 27 Jul 2008 10:37 by Henry
I know what to say now...LOL!!! It all works...!!! Thanks...a bunch!! Henry

Sunday, 27 Jul 2008 10:37 by Dan Bain
I am trying to add the solution for the custom router but I keep getting the following message when I run stsadm from the 12 diectory on the server: Object reference not set to an instance of the object Can you tell me what I am doing wrong?

Sunday, 27 Jul 2008 10:37 by Vince
Dan, Are you trying to add my solution (.wsp)? --Vince

Sunday, 27 Jul 2008 10:37 by Dan
Yes, I am using your .wsp file. I also have a question about Content Types. Can they be made to dynamically change from one folder to another folder inside the same document library? Can they also be made to change dynamically from looking at folder level to the file level? Thank you for your time.

Sunday, 27 Jul 2008 10:37 by Dan
Yes, I am using your .wsp file. I also have a question about Content Types. Can they be made to dynamically change from one folder to another folder inside the same document library? Can they also be made to change dynamically from looking at folder level to the file level? Thank you for your time.

Sunday, 27 Jul 2008 10:37 by Dan
Yes, I am using your .wsp file. I also have a question about Content Types. Can they be made to dynamically change from one folder to another folder inside the same document library? Can they also be made to change dynamically from looking at folder level to the file level? Thank you for your time.

Sunday, 27 Jul 2008 10:37 by MuraliKrishna.n
Hi, I have just tried your code but when I am adding solution its giving error like" The Specified fath is not found" what have I to do?

Thursday, 2 Oct 2008 05:21 by Gopal Chandra Paul
Really good article to start working with custom router. Thanks to the author.

Sunday, 12 Oct 2008 02:20 by

Tuesday, 25 Nov 2008 05:48 by rüya tabiri
Thank you..

Tuesday, 23 Dec 2008 04:10 by

Friday, 26 Dec 2008 10:38 by games secret
thank you::))

Sunday, 4 Jan 2009 04:35 by Chat
thank you :)

Saturday, 10 Jan 2009 07:22 by decatec
Excellent tutorial for the Sharepoint Records Center custon router

Thursday, 5 Mar 2009 09:01 by sohbet odalari
thank you very much

Thursday, 5 Mar 2009 09:14 by sohbet odalari
thank you very much

Saturday, 7 Mar 2009 02:22 by güzel sözler
thank you :)

Saturday, 7 Mar 2009 02:34 by güzel sözler
thank you admin.

Saturday, 7 Mar 2009 03:17 by Sohbet
Thankss

Saturday, 7 Mar 2009 03:26 by Sohbet Odalari
thanks you

Saturday, 7 Mar 2009 03:28 by Mirc
thnks

Friday, 13 Mar 2009 03:47 by Chat
thank youu..

Friday, 13 Mar 2009 04:01 by Chat
thank you canoo

Saturday, 14 Mar 2009 02:15 by granit
Thank you...

Wednesday, 18 Mar 2009 12:20 by Ligtv izle
thank cano

Monday, 23 Mar 2009 06:35 by Mynet
thank you kanka cepten ara beni

Monday, 23 Mar 2009 06:48 by Mynet
canım ya thank valla

Tuesday, 24 Mar 2009 05:05 by Estetik
thank

Wednesday, 25 Mar 2009 07:21 by Dizi izle
thanks admin muck

Saturday, 28 Mar 2009 05:13 by maç izle
thanki you

Monday, 6 Apr 2009 04:06 by ligtv izle
you are my desire..

Monday, 6 Apr 2009 04:13 by ligtv izle
you are my desire..

Monday, 6 Apr 2009 04:14 by ligtv izle
you are my desire..

Sunday, 12 Apr 2009 12:23 by chat
thank you turkish chat34 !

Sunday, 12 Apr 2009 12:41 by chat
thank you turkish chat34 !

Saturday, 18 Apr 2009 12:07 by ligtv izle
thank you

Saturday, 18 Apr 2009 05:13 by esirimsin
thanxx gencler

Tuesday, 28 Apr 2009 03:26 by chat odaları
thankis

Tuesday, 28 Apr 2009 03:33 by chat odaları
thanki

Thursday, 30 Apr 2009 03:06 by sohbet
thank you..

Thursday, 30 Apr 2009 03:07 by sohbet
thank you..

Sunday, 3 May 2009 09:42 by sohbet
thanks

Sunday, 3 May 2009 09:47 by sohbet
thankx

Monday, 4 May 2009 06:27 by justin tv
turkish justin tv..

Monday, 4 May 2009 06:35 by justin tv
turkish justin tv..

Monday, 4 May 2009 06:36 by justin tv
turkish justin tv..

Wednesday, 13 May 2009 04:11 by Sohbet Chat Arkadaşlık
thank you.. www.Foxchat.Gen.Tr

Saturday, 16 May 2009 02:34 by Chat
Thank You

Sunday, 17 May 2009 09:01 by sohbet
hallo i wish you verry succes operator

Tuesday, 19 May 2009 07:43 by Edencity
Thank You Admin

Friday, 22 May 2009 08:08 by lig tv izle
thank

Friday, 22 May 2009 08:13 by lig tv izle
thank you

Sunday, 31 May 2009 03:22 by Sohbet
hallo i wish you verry succes operator

Friday, 5 Jun 2009 05:10 by Sohbet
hallo dear friends thanks a lot for your workshop

Tuesday, 9 Jun 2009 05:07 by Sohbet
hallo i wish you verry succes operator

Monday, 15 Jun 2009 07:26 by sohbet chat
thenks you

Wednesday, 8 Jul 2009 09:40 by islami chat
thank you very much my friends..

Sunday, 12 Jul 2009 09:05 by Araba
Is there even a allegory there both these guys are not even in the aforementioned class. Irfan is arguably one of the best all rounders about and a actual top amount T20 player. Parthiv has had a harder time scoring fast by analysis standards and is apparently not even acceptable for T20. Add to that decidedly added acquaintance that Irfan has arena all-embracing candid and the actuality that he handles preessure able-bodied and its no win for Parhtiv. So if the affair is the adeptness again Parthiv doesnt even appear close, if its about annihilation abroad again able-bodied we can get as artistic as we want.

Tuesday, 11 Aug 2009 04:55 by Aformentioned
That is don't.

Wednesday, 12 Aug 2009 09:44 by sohbet
Thank`s You..

Tuesday, 1 Sep 2009 08:50 by Sohbet
Thanx Admins :)

Tuesday, 1 Sep 2009 08:50 by Sohbet
Thanx Admin How Are You :P

Friday, 9 Oct 2009 07:11 by chat
chat rooms turkish thank you very much..

Thursday, 12 Nov 2009 07:03 by gay sohbet
thanks you admin

Thursday, 12 Nov 2009 07:04 by lez sohbet
tnaks oyu

Sunday, 22 Nov 2009 10:32 by konya chat
thakns admin

Tuesday, 29 Dec 2009 03:52 by estetik
I called this error pretty. But not looking now:))



Url

Email

Comments