ImportContactsL
Login to reply to this topic.
Thu, 2006-02-23 09:36
Joined: 2005-03-03
Forum posts: 52
hi
there has been a lot of querries on the import and export of contacts
the following code works fine for contact cards

EXPORT:
   conFile.Replace(iFs, KContactFile, EFileWrite | EFileShareAny);
   RFileWriteStream fwriteStream(conFile);
//   RFileWriteStream writeStream;
   fwriteStream.Replace(iFs,KContactFile,EFileWrite | EFileShareAny);

   CBufFlat *buf1 = CBufFlat::NewL(1024);

   RBufWriteStream writeStream1(*buf1);

   CContactDatabase* contactsDb = CContactDatabase::OpenL();
   
   
   TUid format;
   format.iUid = KVersitEntityUidVCard;

   CContactIdArray* IdArray1 = 0,*IdArray2 = 0,*IdArray3 = 0;
   CCntFilter *filter = CCntFilter::NewL();
   filter->SetContactFilterTypeCard(ETrue);
   filter->SetContactFilterTypeGroup(EFalse);
   filter->SetContactFilterTypeTemplate(EFalse);
   filter->SetContactFilterTypeOwnCard(ETrue);
   contactsDb->FilterDatabaseL(*filter);


   CBufFlat *buf3 = CBufFlat::NewL(1024);

   RBufWriteStream writeStream1(*buf1);

   contactsDb->ExportSelectedContactsL(format,*(filter->iIds),writeStream3,CContactDatabase::EIncludeX);   HBufC8* temp1 = HBufC8::NewL(buf1->Size()+1);
   TPtr8 ptr1(temp1->Des());
   buf1->Read(0,ptr1,buf1->Size());
   size = temp1->Length();

   TRAP(err, fwriteStream.WriteL((TUint8*)&size, sizeof(size)));

   TRAP(err,fwriteStream.WriteL(ptr1));
   writeStream1.Close();

IMPORT
   file.Open(iFs, KContactFile, EFileRead| EFileShareAny);
   CBufFlat *buf = CBufFlat::NewL(1024);

   //RFileReadStream readStream;
   //readStream.Attach(file);
   //readStream.Open(iFs,KContactFile,EFileRead);
   TInt s;
   file.Size(s);
   HBufC8* temp = HBufC8::NewL(s+1);
   TPtr8 ptr(temp->Des());
   file.Read(ptr,s);
   buf->ExpandL(0,s+1);
   buf->Write(0,ptr,s);
   RBufReadStream readStream(*buf);

   TBool result;
   TUid format;
   format.iUid = KVersitEntityUidVCard;

   CContactDatabase* contactsDb = CContactDatabase::OpenL();
   CleanupStack::PushL(contactsDb);
   
   CArrayPtr<CContactItem>* imported;
    TRAPD(err,imported= contactsDb->ImportContactsL(format, readStream, result, CContactDatabase::EIncludeX|CContactDatabase::ETTFormat|CContactDatabase::EDecreaseAccessCount));
   if(result)
   {
      delete imported;
   }
   CleanupStack::PopAndDestroy();
   delete temp;
   delete buf;
   file.Close();
   iFs.Close();






There are other ways too, byt iterating through the contacts database and getting all the ids and then exporting it.

But In any case you will not be able to eport or import templates and groups with data in it. I mean after exporting and importing, i must have the contacts database with all the groups with members and all the templates i have created.

When i export a template id list, i am not getting the tamplate names similar issue is there with groups too. (you can debug and see the data in the buffer).

Can any one answer the issue of why we are not able to import and export templates and groups?

thanks for the time.
arun

copyright 2003-2009 NewLC SARL