This page was last modified 07:08, 17 April 2008.
CS000900 - Importing a vCard item from a file
From Forum Nokia Wiki
| ID | CS000900 | Creation date | April 17, 2008 |
| Platform | S60 3rd Edition, FP1 | Tested on devices | Nokia N93 |
| Category | Symbian C++ | Subcategory | PIM |
| Keywords (APIs, classes, methods, functions): RFileReadStream, CContactDatabase, CContactItem, CContactDatabase::OpenL(), CContactDatabase::ImportContactsL() |
Overview
This snippet shows a simple function implementation to import one or more vCards from a given file to the default contacts database.
This snippet can be self-signed.
MMP file
The following capabilities and libraries are required:
CAPABILITY WriteUserData
LIBRARY euser.lib LIBRARY estor.lib LIBRARY efsrv.lib LIBRARY cntmodel.lib
Source file
#include <e32cmn.h> //TUid #include <e32std.h> //User #include <e32base.h> //CArrayPtr, CleanupStack #include <e32def.h> //TBool #include <s32file.h> //RFileReadStream #include <f32file.h> //RFs #include <cntdb.h> //CContactDatabase #include <cntitem.h> //CContactItem
TBool ImportVCardL(const TDesC& aFileName) { RFs fileSession; RFile file; TBool result = EFalse; User::LeaveIfError(fileSession.Connect()); CleanupClosePushL(fileSession); if (file.Open(fileSession, aFileName, EFileRead) != KErrNone) { //failed to open the file CleanupStack::PopAndDestroy(); //fileSession return EFalse; } CleanupClosePushL(file); //open a read stream to the file RFileReadStream inputFileStream(file); CleanupClosePushL(inputFileStream); //open the default contacts database CContactDatabase* contactsDb = CContactDatabase::OpenL(); CleanupStack::PushL(contactsDb); //KVersitEntityUidVCard is used to identify a vCard TUid uid = TUid::Uid(KVersitEntityUidVCard); //import one or more vCards from the read stream CArrayPtr<CContactItem>* imported = contactsDb->ImportContactsL(uid, inputFileStream, result, CContactDatabase::ETTFormat); //caller has ownership of the array and frees allocated memory imported->ResetAndDestroy(); delete imported; CleanupStack::PopAndDestroy(4); //contactsDb,inputFileStream, //file,fileSession return result; }
Postconditions
One or more vCards from the given file are imported to the default contacts database. ETrue is returned to the caller or in case of an error, EFalse is returned.
See also
CS000901 - Exporting a vCard item to a file
| Related Discussions | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| List box selected item | vickey | Symbian User Interface | 1 | 2008-03-07 12:38 |
| really urgent problem concnerned ImportContactsL | fanyulong | General Symbian C++ | 4 | 2008-01-07 04:02 |
| Importing from MMP with Carbide.c++ Express 1.1 | goodslaurels | Carbide.c++ and CodeWarrior Tools | 7 | 2007-01-20 20:06 |
| 【请问】如何把CDesCArrarFlat的每一相取出来?? | suxiaoqiang | Symbian | 2 | 2006-08-08 08:32 |
| vCard message through a SMS message for Nokia 7650 | joanlago | General Messaging | 3 | 2002-10-09 14:32 |

