in

Dot Net Mafia

Group site for developer blogs dealing with (usually) .NET, SharePoint 2013, SharePoint 2010, Office 365, SharePoint Online, and other Microsoft products, as well as some discussion of general programming related concepts.

This Blog

Syndication

Archives

Corey Roth [MVP]

A SharePoint MVP bringing you the latest time saving tips for SharePoint 2013, Office 365 / SharePoint Online and Visual Studio 2013.

How to: Create a Workflow to send a file to the Records Center

Today's topic is certainly one of those features that seems like it should be included out of the box.  Luckily, it is pretty simple to implement.  My required was that I needed a file send to the records center whenever it is created, modified, or checked in.  I considered using an ItemEventReceiver, but decided creating a simple workflow would be easier to attach to multiple document libraries.  You could use the same code in an event receiver though.

RecordsCenterWorkflow

My workflow is simple.  It contains an OnWorkflowActivated and a Code activity.  The OnWorkflowActivated activity is only used to set the workflowProperties object.

private void SendOfficialFile(object sender, EventArgs e)

{

    SPFile documentFile = workflowProperties.Item.File;

 

    string recordSeries = documentFile.Item.ContentType.Name;

    string additionalInformation;

    OfficialFileResult fileResult = documentFile.SendToOfficialFile(recordSeries, out additionalInformation);

}

As you can see there really isn't a lot of code required to make this happen.  I simply get the SPFile object from the SPWorkflowProperties object and call its SendToOfficialFile method.  This method takes two parameters, recordSeries and additionalInformation (an out parameter).  It took me a while to find some documentation on what to put in these.  The first example, I saw just left the recordSeries parameter blank.  This will work, but it will also cause all of your files to go to the Unclassified Records routing rule.  After some digging, I discovered you are supposed to set it to the name of the item's content type (which would have a routing rule matching its name).  The OfficialFileResult enum will give you a value of Success if the file was submitted alright, otherwise it will give you a value or MoreInformation which means you can examine the value of the additionalInformation parameter to find out what went wrong.

Once you have your code activity completed, you are ready to compile and deploy the workflow.  Deploy the workflow and attach it to your document library.  Choose wether you want it to execute on new items or modified items.  Once you have done that, you are ready to test it out.  Upload a file or modify an existing one and check your records center to see if the file is there.  Before you start this process, be sure and verify that your records center is functioning to begin with by manually sending a file to the records center with the send to menu option.

At a minimum, this is all that is really required to get a file into the records center.  As usual, I left out exception handling code to keep the post short.  One thing to note, Records Center requires the file to be checked in.  You can choose to handle this.  Some people may not want the file to be sent in the records center, others might want it to just be checked in.  You can determine if the file is checked in by looking at the Level property on the SPFile object.

For more information on handling ShortTerm CheckOut locks, see this post.

Comments

 

Mirrored Blogs said:

Se termina enero, y aqui les dejo un compilado de las mejores ULTIMAS noticias sobre el mundo SharePoint

January 29, 2009 9:26 PM
 

Mike said:

Where are we supposed to write this code?

January 7, 2010 12:03 PM
 

CoreyRoth said:

You can do this by creating a Sequential Workflow in Visual Studio 2008.

January 7, 2010 12:39 PM
 

Ray said:

Hi,

I'm a newbie. Help, please.

Can I copy and paste this into VS2008?

What else do I need to do implement this?

Thanks in advanced

December 17, 2011 8:33 AM
 

CoreyRoth said:

@Ray, you'll have to create those activities like I did.  You can drag them and drop them into the workflow.  If you're not familiar with workflows do a search for a more complete tutorial as there are many steps involved.

January 5, 2012 3:56 PM

Leave a Comment

(required)  
(optional)
(required)  
Add

About CoreyRoth

Corey Roth is an independent SharePoint consultant specializing in ECM, Apps, and Search.
2012 dotnetmafia.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems