The SPFile.SubmitToOfficialFile method enables you to perform the same action as when you use the context menu for an item to click Send To, and then click Official File. This process submits the file to the records center. The method has two overloads the SPFile.SendToOfficialFile (out String) and the SPFile.SendToOfficialFile(String, out String). The methods return an OfficialFileResult from the OfficialFileResult enumeration.
You would typically use the SPFile.SubmitToOfficialFile method as part of a workflow or event handler. By using this method you can automate the submission of a file to the record center. For example you may need to add to the record repository, all files that pass through a publications process. You may edit the workflow for this process to include a call to the SubmitToOfficialFile method. You use the return value provided by the method as part of your conditional logic for further steps. For example, if you receive a return of OfficialFileResult.Success you continue with the workflow, however if you receive the OfficialFileResult.FileCheckedOut you perform other actions.
The following code samples show how to send a file to the official record center for your farm by using the SPFile.SendToOfficialFile method.
SPSite siteCollection = null;SPWeb web = null;
try{ siteCollection = new SPSite("Server");
web = siteCollection.OpenWeb("Site");
SPFile file = web.GetFile("Source_Folder_Name/Source_File");
String recordSeries = "";
String additionalInformation;
OfficialFileResult returnValue;
returnValue = file.SendToOfficialFile(recordSeries, out additionalInformation);
if (returnValue == OfficialFileResult.Success) { //Custom code for user notification }}catch(Exception e){ //Error Handling}finally{ if (web != null) web.Dispose();
if (siteCollection != null) siteCollection.Dispose();}
Dim site As SPSite = NothingDim web As SPWeb = Nothing
Try site = New SPSite("Server") web = site.OpenWeb("Site")
Dim file As SPFile = web.GetFile("Source_Folder_Name/Source_File")
Dim recordSeries As String = ""
Dim additionalInformation As String = ""
Dim returnValue As OfficialFileResult
returnValue = file.SendToOfficialFile(recordSeries, additionalInformation)
If returnValue = OfficialFileResult.Success Then
'Custom code for user notification
End If
Catch e As Exception
'Error Handling
Finally
If Not web Is Nothing Then
web.Dispose()
If Not site Is Nothing Then site.Dispose() End If
End Try