×
Namespaces

Variants
Actions
(Difference between revisions)

Archived:Exporting a vCard item from contacts to a file using Symbian C++

From Nokia Developer Wiki
Jump to: navigation, search
Forum Nokia KB (Talk | contribs)
lpvalente (Talk | contribs)
m (Lpvalente -)
 
(11 intermediate revisions by 5 users not shown)
Line 1: Line 1:
__NOTOC__
+
[[Category:Symbian C++]][[Category:Code Snippet]][[Category:PIM]][[Category:S60 3rd Edition (initial release)]][[Category:Code Snippet]]
__NOEDITSECTION__
+
{{Archived|timestamp=20120314040357|user=roy.debjit| }}
  
{|style="background:#eceff2" width="660px" border="1" cellpadding="5" cellspacing="0"
+
{{ArticleMetaData <!-- v1.2 -->
|-
+
|sourcecode= <!-- Link to example source code (e.g. [[Media:The Code Example ZIP.zip]]) -->
|'''ID''' || &nbsp;
+
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
|'''Creation date''' || April 9, 2008
+
|devices= Nokia N93
|-
+
|sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) -->
|'''Platform''' || S60 3rd Edition, FP1
+
|platform= S60 3rd Edition, FP1
|'''Tested on devices''' || Nokia N93
+
|devicecompatability= <!-- Compatible devices (e.g.: All* (must have GPS) ) -->
|-
+
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
|'''Category''' || Symbian C++
+
|signing= <!-- Empty or one of Self-Signed, DevCert, Manufacturer -->
|'''Subcategory''' || PIM
+
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
|}
+
|keywords= RFileWriteStream, CContactDatabase, CContactIdArray, CCntFilter, CContactDatabase::OpenL(), CContactDatabase::ExportSelectedContactsL(), CContactDatabase::FilterDatabaseL(), CCntFilter::SetContactFilterTypeALL(), CCntFilter::SetContactFilterTypeCard()
 
+
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 
+
|translated-by= <!-- [[User:XXXX]] -->
{|style="background:#eceff2" width="660px" border="1" cellpadding="5" cellspacing="0"
+
|translated-from-title= <!-- Title only -->
|-
+
|translated-from-id= <!-- Id of translated revision -->
|'''Keywords (APIs, classes, methods, functions):''' RFileWriteStream, CContactDatabase, CContactIdArray, CCntFilter, CContactDatabase::OpenL(), CContactDatabase::ExportSelectedContactsL(), CContactDatabase::FilterDatabaseL(), CCntFilter::SetContactFilterTypeALL(), CCntFilter::SetContactFilterTypeCard()
+
|review-by= <!-- After re-review: [[User:username]] -->
|}
+
|review-timestamp= <!-- After re-review: YYYYMMDD -->
 +
|update-by= <!-- After significant update: [[User:username]]-->
 +
|update-timestamp= <!-- After significant update: YYYYMMDD -->
 +
|creationdate= 20080409
 +
|author= [[User:Aknyman]]
 +
<!-- The following are not in current metadata -->
 +
|subcategory= PIM
 +
|id= CS000901
 +
}}
  
 
==Overview==
 
==Overview==
  
This snippet shows a simple function implementation to export one contact from the default contacts database as vCard to the given file.
+
{{Abstract|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.
 
This snippet can be self-signed.
Line 35: Line 43:
  
 
<code>
 
<code>
LIBRARY euser.lib
+
LIBRARY euser.lib
LIBRARY estor.lib  
+
LIBRARY estor.lib  
LIBRARY efsrv.lib
+
LIBRARY efsrv.lib
LIBRARY cntmodel.lib
+
LIBRARY cntmodel.lib
 
</code>
 
</code>
  
Line 121: Line 129:
  
 
==Postconditions==
 
==Postconditions==
One contact given by index from the default contacts database is exported as a vCard to the given file.
+
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 in success case or EFalse when the file creation fails.  
+
  
==See also==
+
The function returns ETrue to the caller when the file creation succeeds or EFalse when the file creation fails.
[[Importing_vCard_item_from_a_file]]
+
  
[[Category:Symbian C++]][[Category:Code Examples]][[Category:PIM]]
+
==See also==
 +
[[Archived:Importing a vCard item into the contacts database from a file using Symbian C++]]

Latest revision as of 21:13, 11 August 2012

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: RFileWriteStream, CContactDatabase, CContactIdArray, CCntFilter, CContactDatabase::OpenL(), CContactDatabase::ExportSelectedContactsL(), CContactDatabase::FilterDatabaseL(), CCntFilter::SetContactFilterTypeALL(), CCntFilter::SetContactFilterTypeCard()
Created: aknyman (09 Apr 2008)
Last edited: lpvalente (11 Aug 2012)

Contents

[edit] 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.

[edit] MMP file

The following capabilities and libraries are required:

CAPABILITY ReadUserData
LIBRARY euser.lib
LIBRARY estor.lib
LIBRARY efsrv.lib
LIBRARY cntmodel.lib

[edit] 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;
}

[edit] 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.

[edit] See also

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

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

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×