Archived:Importing a vCard item into the contacts database from a file using Symbian C++
Archived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.
Contents |
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
Archived:Exporting a vCard item from contacts to a file using Symbian C++


(no comments yet)