You Are Here:

Community: Wiki

This page was last modified on 9 October 2008, at 17:14.

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 Wiki Articles

No related wiki articles found

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia