×
Namespaces

Variants
Actions
Revision as of 21:13, 11 August 2012 by lpvalente (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Archived:Importing a vCard item into the contacts database from a file using Symbian C++

From Nokia Developer Wiki
Jump to: navigation, search

Archived.pngArchived: 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}}.

Article Metadata
Tested with
Devices(s): Nokia N93
Compatibility
Platform(s): S60 3rd Edition, FP1
S60 3rd Edition (initial release)
Article
Keywords: RFileReadStream, CContactDatabase, CContactItem, CContactDatabase::OpenL(), CContactDatabase::ImportContactsL()
Created: aknyman (09 Apr 2008)
Last edited: lpvalente (11 Aug 2012)

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++

This page was last modified on 11 August 2012, at 21:13.
70 page views in the last 30 days.
×