×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Regular Contributor
    Join Date
    Nov 2009
    Posts
    371

    Thumbs up Convert the contacts to csv format

    Hi,
    I am fetching all the contacts from device.I want to store these contacts in csv format.Can u tel me how can i do this in symbian.

  2. #2
    Super Contributor
    Join Date
    Mar 2004
    Location
    Singapore
    Posts
    9,968

    Re: Convert the contacts to csv format

    which part you are getting problem,

    1. fetching all the contacts from device (example in wiki)
    2. tore these contacts in csv format (write to a file example in wiki)

  3. #3
    Regular Contributor
    Join Date
    Nov 2009
    Posts
    371

    Re: Convert the contacts to csv format

    I need in step 2.
    i.e., to tore these contacts in csv format

  4. #4
    Super Contributor
    Join Date
    Mar 2004
    Location
    Singapore
    Posts
    9,968

    Re: Convert the contacts to csv format

    Quote Originally Posted by prathi View Post
    I need in step 2.
    i.e., to tore these contacts in csv format
    just dump all fields one after another separated by ',' at the and of each record (contact) you have to use \n or (\n\r)

  5. #5
    Regular Contributor
    Join Date
    Nov 2009
    Posts
    371

    Re: Convert the contacts to csv format

    ok i had done that and stored it in one buffer.next what i need to do?

  6. #6
    Super Contributor
    Join Date
    Mar 2004
    Location
    Singapore
    Posts
    9,968

    Re: Convert the contacts to csv format

    you can write it to a file and show us.

    note: you can directly write to a file,.

  7. #7
    Regular Contributor
    Join Date
    Nov 2009
    Posts
    371

    Re: Convert the contacts to csv format

    I had fetched the data from contacts and sepated by comma is shown below.

    TBuf<3000> contactdata;
    TBuf8<4000> totalcontact;
    contactdata.Copy(_L("Firstname"));
    contactdata.Append(_L(","));
    contactdata.Append(_L("Lastname"));
    contactdata.Append(_L(","));
    contactdata.Append(_L("Number"));
    contactdata.Append(_L(","));
    contactdata.Append(_L("Number 1"));
    contactdata.Append(_L(","));
    contactdata.Append(_L("Number 2"));
    contactdata.Append(_L(","));
    contactdata.Append(_L("Email"));
    contactdata.Append(_L(","));
    contactdata.Append(_L("Email1"));
    contactdata.Append(_L(","));
    contactdata.Append(_L("Web"));
    contactdata.Append(_L(","));
    contactdata.Append(_L("Company"));
    contactdata.Append(_L(","));
    contactdata.Append(_L("Address"));
    contactdata.Append(_L(","));
    contactdata.Append(_L("Address1"));
    totalcontact.Copy(contactdata);
    CSVfile(totalcontact);

    In CSVfile(TDesC8& data)
    {
    RFs fs;
    fs.Connect();
    RFile hist;
    TBuf<300> iLine;
    if (hist.Open(fs, KCSVFile, EFileRead) == KErrNone)//where KCSVFile == _LIT(KCSVFile,"E://location.csv");
    {
    hist.Write(data);
    hist.Close();
    }

    }
    is this correct.please tel me.

  8. #8
    Super Contributor
    Join Date
    Mar 2004
    Location
    Singapore
    Posts
    9,968

    Re: Convert the contacts to csv format

    Do remove TBuf<> with HBufC* also where is the contact data you are writing.

  9. #9
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,674

    Re: Convert the contacts to csv format

    Open: opens an existing file, returns with KErrNotFound otherwise - I guess this is what is happening
    Create: creates a new file, returns KErrAlreadyExists otherwise
    Replace: creates a new file, even if an old one exists
    Of course all of them are subject to KErrPathNotFound, and KErrAccess/PermissionDenied, but in case of e:\, they are unlikely appear.
    There is a Temp too, which is a Create/Replace with an automatically generated, unique file name.

    EDIT: Skumar_rao is right about the descriptors, they are too large for being local variables.

  10. #10
    Regular Contributor
    Join Date
    Nov 2009
    Posts
    371

    Re: Convert the contacts to csv format

    contact data i had not put i had put the heading names as firstname,lastname etc.and where KCSVFile == _LIT(KCSVFile,"E://location.csv");in which location.csv will create by it self or what?where to see the csv files generated one.

  11. #11
    Super Contributor
    Join Date
    Mar 2004
    Location
    Singapore
    Posts
    9,968

    Re: Convert the contacts to csv format

    Quote Originally Posted by prathi View Post
    contact data i had not put i had put the heading names as firstname,lastname etc.and where KCSVFile == _LIT(KCSVFile,"E://location.csv");in which location.csv will create by it self or what?where to see the csv files generated one.
    no it will not ... if you have the file only then it will open it ... i suggest you refer to wiki post for how to open and write to a file.

  12. #12
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,674

    Re: Convert the contacts to csv format

    Just to make sure: are they \\ ? They should.

  13. #13
    Regular Contributor
    Join Date
    Nov 2009
    Posts
    371

    Re: Convert the contacts to csv format

    thanks for your reply,i had successfully created the csv file.but the data to first row will insert,i want to insert the second contact to next line but when ever the data is about to write the app is crashing with kern-exec.

    this is my code.
    totalcontact.Copy(contactvaluptr);//contactvaluptr has the data of contact phone number etc.
    LOGDES16(totalcontact);
    CSVfile(totalcontact);
    /*totalcontact.Zero();
    totalcontact.Append(_L("\n"));*/


    }
    CleanupStack::PopAndDestroy(2); // contact contactsDb
    LOGEXIT;
    }

    void CEventsContacts::CSVfile(TDesC8& data)
    {
    LOGENTER;

    RFs fs;
    RFile hist;
    User::LeaveIfError(fs.Connect());
    if(!BaflUtils::FileExists(fs,KCSVFile))
    {
    LOGTXT("FILE EXITS");
    hist.Create(fs, KCSVFile, EFileShareAny);
    }
    LOGTXT("EFileShareAny");
    hist.Write(data);//here crashing while writing the data to secon time.
    data.Alloc()->Des().Append(_L("\r\n"));
    LOGDES16(data.Alloc()->Des());
    hist.Close();

    LOGEXIT;

    }
    please help me how to continue writing in next line.

  14. #14
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,674

    Re: Convert the contacts to csv format

    Your code is full of problems, that can be a reason. KERN-EXEC does not mean anything without the number.
    - you are creating the file if it does not exist. It happens on the first time, but obviously on the second attempt it exist, so you are writing to a file which has not been opened
    - if hist.Write(data) compiles, data is a 8-bit descriptor, so passing it to LOGDES16 is strange
    - data.Alloc() allocates a copy of the descriptor on the heap, you are probably having 2 memory leaks
    - since data.Alloc() allocates memory for the descriptor, appending 2 extra characters may or may not succeed, but you are losing the result anyway, so it makes no sense

  15. #15
    Super Contributor
    Join Date
    Mar 2004
    Location
    Singapore
    Posts
    9,968

    Re: Convert the contacts to csv format

    1. your file write will fail if file does not exist ... try if creating the file if you get a file file exists error then you can open it.
    2. to write to next line you can make "hist" as class member and open it at the starting and close only once all are done.
    3. or you can open the file and seek to end of the file before writing .

Similar Threads

  1. How to write data in CSV format through J2ME coding
    By aparna_bhure in forum Mobile Java General
    Replies: 2
    Last Post: 2009-09-24, 08:21
  2. PC Suite 4.5 - backup contacts into a CSV file, outlook or other.
    By Briano in forum General Development Questions
    Replies: 2
    Last Post: 2008-02-06, 06:08
  3. Contacts DB to CSV format
    By kiranpuranik in forum Symbian
    Replies: 3
    Last Post: 2008-01-14, 11:55
  4. CSV format & phone book
    By m_pahlevanzadeh in forum Tools and SDK Feedback (Closed)
    Replies: 1
    Last Post: 2007-07-29, 17:26
  5. How to edit Content Copier phonebook.csv. What is the format of the file?
    By dflick in forum PC Suite API and PC Connectivity SDK
    Replies: 1
    Last Post: 2002-08-14, 12:58

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×