Symbian3/SDK/Source/GUID-082E47B3-8AAB-51B7-93F9-3C528B97D0A9.dita
author Dominic Pinkman <Dominic.Pinkman@Nokia.com>
Thu, 21 Jan 2010 18:18:20 +0000
changeset 0 89d6a7a84779
permissions -rw-r--r--
Initial contribution of Documentation_content according to Feature bug 1266 bug 1268 bug 1269 bug 1270 bug 1372 bug 1374 bug 1375 bug 1379 bug 1380 bug 1381 bug 1382 bug 1383 bug 1385

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. -->
<!-- This component and the accompanying materials are made available under the terms of the License 
"Eclipse Public License v1.0" which accompanies this distribution, 
and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". -->
<!-- Initial Contributors:
    Nokia Corporation - initial contribution.
Contributors: 
-->
<!DOCTYPE concept
  PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
<concept xml:lang="en" id="GUID-082E47B3-8AAB-51B7-93F9-3C528B97D0A9"><title>How to Export Contact and Calendar Data</title><prolog><metadata><keywords/></metadata></prolog><conbody><p>The versit API provides support for exporting contact and calendar data to a stream. For example, suppose you want to make changes to an existing contact or calendar entry, and export the same to an external file store. To do so, again create the appropriate parser objects. That is, <xref href="GUID-F4BEE3F4-F268-345D-B727-2C1D5E25F3F7.dita"><apiname>CParserVCard</apiname></xref> and <xref href="GUID-6BEFF6A7-FBD8-306D-98A4-8711E788C702.dita"><apiname>CParserVCal</apiname></xref> objects to export vCards and/or vCalendars. For more information on importing vCard and vCalendar, refer to <xref href="GUID-2A39CCBD-CADB-56B7-872A-1EC617AC7D93.dita">How to Import Contact and Calendar Data</xref>. </p> <p>Let us assume that, you want to add a new property to the vCard called <i>EMAIL</i> with the parameters <i>ENCODING</i> and <i>CHARSET</i>, and the property value of <i>foo@bar.org</i>. To do so, you need to create objects of <xref href="GUID-895C3D03-FE10-329C-9437-2948686509C5.dita"><apiname>CParserProperty</apiname></xref>, an array of <xref href="GUID-4A02E5BD-39D3-34AD-B70B-8177144FF12C.dita"><apiname>CParserParam</apiname></xref> to hold parameter information, and <xref href="GUID-76E6CCFA-5BAC-34F1-A5B2-FB505A68E784.dita"><apiname>CParserPropertyValue</apiname></xref> to hold the property values. </p> <codeblock id="GUID-B97F4C10-25A1-504E-A072-5E65EA5EEB73" xml:space="preserve">// String literals representing the property and its value.
_LIT(KPName,"EMAIL");
_LIT(KEmail,"foo@bar.org");

// String literals representing the property parameters and their values.
_LIT(KParam1,"ENCODING");
_LIT(KValue1,"QUOTED-PRINTABLE");
_LIT(KParam2,"CHARSET");
_LIT(KValue2,"US-ASCII");

CParserPropertyValue* value=CParserPropertyValueHBufC::NewL(KEmail); // The property value.

// Array to hold parameters of EMAIL property.
CArrayPtr&lt;CParserParam&gt;* arrayOfParams = new(ELeave)CArrayPtrFlat&lt;CParserParam&gt;(2);

// Parameters with their corresponding values are added to the array.
CParserParam* parserParam1=CParserParam::NewL(KParam1,KValue1);
arrayOfParams-&gt;AppendL(parserParam1);
CParserParam* parserParam2=CParserParam::NewL(KParam2,KValue2);
arrayOfParams-&gt;AppendL(parserParam2);

// Associate the property params and property value with the EMAIL property
CParserProperty* property=CParserProperty::NewL(*value,KPName,arrayOfParams);

// Finally add the EMAIL property to the vCard using the parser object.
vCardParser-&gt;AddPropertyL(property);

// Set the character set as ASCII (7-bit) for transformation.
vCardParser-&gt;SetDefaultCharSet(Versit::EUSAsciiCharSet);</codeblock> <p> <i>Note that you should include proper error checks in the above given code before using it for production.</i>  </p> <p>Once you have added the EMAIL property, you can externalize (export) the vCard. This time you have to open the file in write mode to externalize the vCard data. </p> <codeblock id="GUID-639AAC10-2332-5408-86F8-24045A3F0094" xml:space="preserve">TInt err = file.Replace(iFsSession, KVCardFileJIS, EFileWrite) // Replace the file with modified information.
// Check if there is any error reported before exporting the vCard.
if(err == KErrNone)
   vCardParser-&gt;ExternalizeL(file);</codeblock> <p>Same procedure could be followed if you want to modify a vCalendar using the <codeph>CParserVCal</codeph> object. </p> </conbody></concept>