Join Now
Quality Rating:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)
Expertise Level:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)

This page was last modified 07:11, 17 April 2008.

CS000901 - Exporting a vCard item to a file

From Forum Nokia Wiki


ID CS000901 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): RFileWriteStream, CContactDatabase, CContactIdArray, CCntFilter, CContactDatabase::OpenL(), CContactDatabase::ExportSelectedContactsL(), CContactDatabase::FilterDatabaseL(), CCntFilter::SetContactFilterTypeALL(), CCntFilter::SetContactFilterTypeCard()

Overview

This snippet shows a simple function implementation to export one contact from the default contacts database as a vCard to a given file.

This snippet can be self-signed.

MMP file

The following capabilities and libraries are required:

CAPABILITY ReadUserData
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 <cntdef.h>   //CContactIdArray
#include <cntfilt.h>  //CCntFilter
TBool ExportVCardL(const TDesC& aFileName, TInt aItemIndex)
{
  RFs fileSession;
  RFile file;
    
  User::LeaveIfError(fileSession.Connect());
  CleanupClosePushL(fileSession);
 
  if (file.Replace(fileSession, aFileName, EFileWrite) != KErrNone)
      {
      //failed to create the file
      CleanupStack::PopAndDestroy(); //fileSession
      return EFalse;
      }
  CleanupClosePushL(file);
 
  //open a write stream to the file
  RFileWriteStream outputFileStream(file);
  CleanupClosePushL(outputFileStream);
 
  //open the default contacts database
  CContactDatabase* contactsDb = CContactDatabase::OpenL();
  CleanupStack::PushL(contactsDb);
            
  //create an array of contact IDs to export
  CContactIdArray* exportContacts = CContactIdArray::NewL();
  CleanupStack::PushL(exportContacts);
            
  //use a filter to get only contact items (e.g. templates are excluded)
  CCntFilter *filter = CCntFilter::NewLC();
  filter->SetContactFilterTypeALL(EFalse);
  filter->SetContactFilterTypeCard(ETrue);
  contactsDb->FilterDatabaseL(*filter);
            
  //create an array to hold all filtered contact items
  CContactIdArray* contactIds;
  contactIds = CContactIdArray::NewLC(filter->iIds);
    
  //add given contact(by index) to the array of contact IDs to export 
  if((*contactIds).Count() >= aItemIndex)
      exportContacts->AddL((*contactIds)[aItemIndex] );            
            
  CleanupStack::PopAndDestroy(2); //contactIds, filter
            
  //KVersitEntityUidVCard is used to identify a vCard
  TUid uid = TUid::Uid(KVersitEntityUidVCard);
  contactsDb->ExportSelectedContactsL(uid,
                                      *exportContacts,
                                       outputFileStream,
                                       //contact ID is no exported 
                                       CContactDatabase::EExcludeUid);
 
  CleanupStack::PopAndDestroy(5); //exportContacts,contactsDb, 
                  //outputFileStream,file,fileSession 
    
  return ETrue;
}

Postconditions

A contact given by the index from the default contacts database is exported as a vCard to the given file.

The function returns ETrue to the caller when the file creation succeeds or EFalse when the file creation fails.

See also

CS000900 - Importing a vCard item from a file

Related Discussions
Thread Thread Starter Forum Replies Last Post
VCal and VCard (Bluetooth) koayst General Symbian C++ 1 2004-02-24 22:16
Send Pictures or Melodies directly to the phone. Nokia_Archive Symbian Networking & Messaging 2 2002-05-20 12:47
Send Vcard from PC to Phone thaker General Messaging 1 2006-05-04 04:19
How to get an object through Obex. lal.rajan Symbian Networking & Messaging 2 2007-02-17 12:19
SettingList koayst General Symbian C++ 0 2003-06-29 03:33
 
Powered by MediaWiki