The versit API can be used to import Contact and/or Calendar data from a file or stream. To do so, appropriate parser objects have to be created. That is, an object of CParserVCard class to import vCards (represents contact data) and object of CParserVCal class to import vCalendars (represents calendar data) need to be created.
CParserVCard* vCardParser = CParserVCard::NewL(); //creates a pointer to CParserVCard object //OR CparserVCal* vCalParser = CParserVCal::NewL(); //creates a pointer to CParserVCal object
Once the parser objects are created, specify the stream from which the vCard or vCalendar are to be read. For example, let us assume that you have to import vCard or vCalendar from a file. In that case, create an object of RFile class to read the file, and an object of RFs class to create a file server session. You also have to create an object of RFileReadStream class, as the parser class is implemented to read data from a stream.
RFs iFsSession; // To create file server session. RFile file; // To access the vCard or vCal file from the file system. _LIT(KVCardFileJIS,"c:\\charsetJIS.vcf "); // String literal consisting the path of the file to be read. TInt err=file.Open(iFsSession, KVCardFileJIS, EFileRead); // Open the file to be read. // Checking for errors if any, before opening the file stream. if(err == KErrNone) { RFileReadStream stream(file); // Opens the file stream for the RFile object. vCardParser.InternalizeL(stream) // To import a vCard. // OR vCalParser.InternalizeL(stream) // To import a vCal. stream.close(); // Close the file stream once the import is done. }
Note that you should include proper error checks in the above given code before using it for production.
This code imports vCard and vCalendar data from the file to CParserVCard
and CParserVCal
objects respectively.