February 27, 2021
Hot Topics:

Records Management for Microsoft Office SharePoint Server

  • By Gustavo Velez
  • Send Email »
  • More Articles »

To upload a document to the Records Center using the Object Model, use code similar to the following routine (the routine can be used in a Console application directly, or by modifying the output, in any other type of application):

static void SendDocumentToRecordsCenterOM()
      string AdditionalInformation = string.Empty
      OfficialFileResult OperationResult;

      SPSite mySite = new SPSite("http://ServerName");
      SPWeb myWeb = mySite.OpenWeb();

      SPFile myDoc = myWeb.GetFile("LibreryDoc/DocName.docx");

      OperationResult =
         myDoc.SendToOfficialFile(out AdditionalInformation);

      Console.WriteLine("Operation State: " + OperationResult);
   catch (Exception ex)
      Console.WriteLine("Error - " + ex.ToString());
Note: Set references to "Windows SharePoint Services" (Microsoft.SharePoint.dll) and a Directive to "using Microsoft.SharePoint".

"AdditionalInformation" is a variable (string) necessary to send complementary information about the document to the Records Center; "OperationResult" is other variable (OfficialFileResult) that saves the results of the upload operation, indicating its success completion or if there was an error (the values can be FileCheckedOut, FileRejected, InvalidConfiguration, MoreInformation, NotFound, Success, or UnknownError).

Two Objects of the type SPSite and SPWeb are created to make a reference to the document ("myDoc", of the SPFile type) that uploads to the Center. Finally, the "SendToOfficialFile" Method of the SPFile Class takes care of the upload procedure and signals the results of the action.

To suspend or reactivate a document in the Records Center, follow this procedure:

static void HoldRegister()
   SPSite mySite = new SPSite("http:// ServerName:Port");
   SPWeb myWeb = mySite.OpenWeb();

   SPList myListRetension = Hold.GetHoldReportsList(myWeb);

   int SuspensionID = 0;
   foreach(SPListItem oneRetension in myListRetension.Items)
      if(oneRetension.Name.Contains("Suspension for Notary
         Documents") == true)
      SuspensionID = oneRetension.ID;

   SPList NotaryCenter = miWeb.Lists["Notary Center"];
   SPListItem DocToSuspend = null;

   foreach(SPListItem oneDoc in NotaryCenter.Items)
      if (oneDoc.Name.Contains("One document for the Register")
         == true &&
         oneDoc.Name.Contains(".docx") == true)
            DocToSuspend = oneDoc;

   Hold.SetHold(SuspensionID, DocToSuspend,
      "Made with the Object Model");
Note: In addition to the reference to the SharePoint DLL, the code requires a reference to "Microsoft Office Server DLL Component" (Microsoft.Office.Policy.dll) and a directive to "using Microsoft.Office.RecordsManagment.Holds."

First, the code creates SPSite and SPWeb Objects to contain the Records Center. The variable "myListRetension" (SPList) is a reference to the Holds List used in the Center, and the loop locates the identifier (integer) of the Holds Police. In the example, the name of the policy is used, but there are other possibilities, probably more effective, as a query against the List.

In a similar way, a reference to the Library ("Notary Center") containing the document to Hold is created together with the Object that contains the document ("DocToSuspend" of the type SPListItem). Finally, the "SetHold" method of the "Hold" Class (Microsoft.Office.RecordsManagement.Holds) places the document 'on hold', adding a comment if desired. An override of SetHold is used to 'on hold' the documents contained in a "SPListItemCollection", should a bulk document suspension be necessary.

The "ReleaseHold" Method utilizes the identifier of the Hold and uses a reference to the SPWeb of the Library containing the document and the comment as parameters; together, they delete the Hold on the document. The Object Model contains a "RemoveHold" Method, but it is only for internal MOSS use.

Programming the Records Center Utilizing WebService

In the event the MOSS Object Model cannot be used, SharePoint has a default WebService to upload documents to the Records Center. The next routine will upload a document in this way:

static void SendDocumentToRecordsCenterWS()
   RegisterCenterWS.RecordsRepository myCentroRegistrosWS = 
     new RegisterCenter.RegisterCenterWS.RecordsRepository();
   myRegisterCenterWS.Url =
   myRegisterCenterWS.Credentials =

   SPSite mySite = new SPSite("http://ServerName");
   SPWeb myWeb = mySite.OpenWeb();

   SPFile myDoc = myWeb.GetFile("Document to register/One document
                                 to Register.docx");
   byte[] myDocByte = myDoc.OpenBinary();

      RepositoryProperties =
      new RegisterCenter.RegisterCenterWS.RecordsRepositoryProperty[1]; 

   RepositoryProperties[0] =
      new RegisterCenter.RegisterCenterWS.RecordsRepositoryProperty();
   RepositoryProperties[0].Name = "Send by";
   RepositoryProperties[0].Type = "Text";
   RepositoryProperties[0].Value = myDoc.Author.LoginName;

   string OperacionResult =
      myRegisterCenterWS.SubmitFile(myDocByte, RepositoryProperties,
      "Notary Document ", myDoc.Url, myDoc.Author.LoginName);

   Console.WriteLine("Operation Result: " + OperationResult);

Page 3 of 4

This article was originally published on November 21, 2008

Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date