Friday, November 11, 2011

SharePoint 2010: Programmatically send a file to the records center

If you want to send a file to a Records Center, whether it's a sub site or a seperate site collection, you can use the following code:

string additionalInformation = string.Empty;

SPOfficialFileHost ofh = new SPOfficialFileHost();
ofh.Action = SPOfficialFileAction.Move;
ofh.OfficialFileName = item.File.Name;
ofh.OfficialFileUrl = new Uri("http://yourserver/sites/RecordsCenter");

OfficialFileResult returnValue = item.File.SendToOfficialFile("Content-type", ofh, "", SPOfficialFileSubmissionMode.ExpirationPolicy, out additionalInformation);

if (returnValue != OfficialFileResult.Success)
{
throw new Exception("Error sending file to records center: " + additionalInformation);
}