API Code Snippet - Add Documents with Metadata

Sunday, May 11, 2008

Sometimes customers will integrate the FileHold document management software system with other systems, databases and applications in their network or enterprise. While the majority of our wide ranging customer base use FileHold Document Management Software out of the box, there are customer examples who require an API for integration into other systems. For example, we have customers that have integrated with SAP, GlobalShop ERP, Java based systems via SOAP, Oracle E-Business Suite Financials, MS SharePoint, and custom intranet applications as well as various types of corporate enterprise information portals.

FileHold is a Microsoft dot net based system designed around a scalable highly configurable web services oriented architecture. This post features a useful code snippet that shows how you can add a document to the FileHold document management software system via the FileHold web services based API. It illustrates using the FieldWithValues structure required by the AddDocument method of the Document Manager service.

TIP: A code snippet is an small piece of code extracted from a larger program. It is not fully functional on its own.

// ----------- start of code snippet
// get the fields definition for the schema

FieldDefinition[] fielddefinitions = DocumentSchemaManager.GetDocumentSchemaFields( SchemaId );

// create the new schema values for the document

List fieldsWithValues = new List();

// for each schema field

foreach ( FieldDefinition field in fielddefinitions )
// only do for NON system fields
    if ( !field.IsSystem )
        FieldWithValue newFieldValue = new FieldWithValue();

// global field id

        newFieldValue.FieldId = field.MetadataFieldId;

// define variable ob type object

        object value = null;

// and now based on the field type assign the value

// if you want to assign default value

//      value = field.InitialValue;

// if it is string

//      value = "text of the metadata"

// if it is date

//      DateTime dt = new DateTime( 2008, 4, 12 );
//      value = dt;

// in case of dropdown menu get the menu items into array

//      DropdownFieldChoice[] menuchoices = DocumentSchemaManager.GetDropDownMenuItems( field.MetadataFieldId );
//      set the default null value
//      value = new int[] { };
//      foreach (DocumentSchemaManagerService.DropdownFieldChoice menu in menuchoices )
//      {
//          if (menu.Value == YOU_MENU_FIELD_VALUE )
//          {
//              value = new int[] { menu.Id };
//              break;
//          }
//      }

// set the value

        newFieldValue.FieldValue = value;

// add the field value to the list

        fieldsWithValues.Add( newFieldValue );

// now you can use the fieldsWithValues variable in the AddDocument method

// ----------- end of code snippet