Dynamic data import / export

datenbank

simply more productive
Up to 10,000 records can be processed with the freeware version!

Import/Export vCard (line based) text files

With this example we wish to demonstrate how to import and export vCard (contact data) version 2.1 files. Commonly referred to as electronic business cards, vCards can typically be imported into and exported from email clients.

The format of vCards is line-based, which means that each value is stored on a separate line (or several lines). The first vCard line is introduced with the keyword BEGIN:VCARD and the data ends with a line containing the keyword END:VCARD. All information on lines between these two keywords is data in vCard format pertaining to the contact.

Reading (importing) a vCard file

To read (import) a vCard file is relatively easy with the help of the FlowHeater TextFile Adapter. The TextFile Adapter automatically detects when you select a vCard (.vcf) file on the READ side and sets the standard options by default.

Standard options for vCard import

  • General tab: Delimitation is set to "Line based"
  • Line-based options tab: "Each line contains field names" is checked
  • Line-based options tab: The "Field / contents separator character" is predefined with a colon (:)
  • Line-based options tab: Content recognition is set to "Start/end detection"
  • Line-based options tab: Content begins with is predefined as "BEGIN:VCARD"
  • Line-based options tab: Content ends with is predefined as "END:VCARD"
  • Advanced tab: Option "Permit line breaks in columns" is checked
  • Advanced tab: Option "Replace line breaks with" is checked and an empty string entered

After selecting the vCard file you see in the preview the field information input. The field names contain the vCard properties including any potentially additional parameters.

e.g. for telephone TEL;WORK;VOICE

Here "TEL" is the property type for telephone. "WORK" and "VOICE" are parameters that define this property more precisely. In this instance the number for voice calls at the place of work.


Reading (importing) embedded image data in a vCard

Sometimes picture data embedded in vCard files are encoded as BASE64, in our example the property "PHOTO;TYPE=JPEG;ENCODING=BASE64" introduces this. If you want to store the data as an image file (.jpg) or import it to a VARBINARY or BLOB field in a database table then the BASE64 picture data must first be decoded. We need a .NET Script Heater containing the short script that follows to perform the decoding. The output of this Heater we can either connect to a File Heater to write an external image file or import it directly to a database field with the FlowHeater data type RAW (in SQL a VARBINARY or BLOB).

public object DoWork()
{
  int count = InValues.Length;
  if (count != 1)
    throw new Exception("1 input parameter expected!");

  string base64 = (string)InValues[0].GetString();

  if (base64 == null)
    return null;

  // remove spaces!
  base64 = base64.Replace(" ", "");

  return Convert.FromBase64String(base64);
}

 

Writing (exporting) vCards

available soon!