| 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() |
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.
The following capabilities and libraries are required:
CAPABILITY WriteUserData
LIBRARY euser.lib
LIBRARY estor.lib
LIBRARY efsrv.lib
LIBRARY cntmodel.lib
#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;
}
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.
No related wiki articles found