Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
Posts: 134
Registered: ‎01-25-2010
My Device: Z30, Z10, Q10, Dev Alpha B & Bold 9900
My Carrier: Bell
Accepted Solution

Creating a csv files, then sending file has an attachment ...

I have a multi-segment question...

I need to create a csv file, and then attach this file to an email. I have a broad idea on how to get this going, but before I start coding I have a few questions...

 

Here are the classes / pseudo code...

 

  1. Create file, overwrite any existing because only need one instance of this file...

      QString csvFile = QDir::homePath() "/mycsvFileAttachement.csv" ;
      QFile newFile(csvFile);

  2. Loop throught data model, and write each record to file

    Not certain how to accomplish this part with C++. Any sample to demonstrate how to accomplish this ?

  3. Create new email and attach the newly created file... So, for this piece I was looking @ the MessageBuilder class...

    https://developer.blackberry.com/cascades/reference/bb__pim__message__messagebuilder.html

    It would have been so much simply to have the ability to use the invoke framework to push a new message UI, but from what I've been reading, it's basically impossible to hook up an attachment via the invoke framework. Is that correct?

  4. Display New Message UI, and wait until the message is fired off... by user :smileyhappy:

    https://github.com/blackberry/Cascades-Samples/tree/master/messages

    For sending an email, the message sample provides me all the required code to accomplish this functionality. But I would also like to provide a contact picker to the user, any sample that would demonstrate how to accomplish this ?
Regular Contributor
Posts: 94
Registered: ‎12-02-2011
My Device: non-Blackberry user
My Carrier: none

Re: Creating a csv files, then sending file has an attachment ...

[ Edited ]

If the file save location is important you best prompt the user with the FileSelector dialog.  They may save it under documents or to SD card, etc.  If not then create a temp file, that is do not use QDir::homePath();

 

 

filePicker = new FilePicker();
filePicker->setType(FileType:: other);

 

// connect to this so can at least do a deleteLater()

connect(filePicker,SIGNAL(canceled()),this,SLOT(filePickerCanceledSlot()));

 

// connect here to get name of file to save to
 connect(filePicker,SIGNAL(fileSelected(const QStringList &)),
                this,SLOT(filePickerSelectedSlot(const QStringList)));

 

As far as writing to the file, Use QTextStream to help you.  Do something like this:

 

QFile file(fileName);
    bstatus = file.open(QIODevice::WriteOnly);
    if (!bstatus) {
        qWarning() << "Failed to open file " << fileName;
        return;
    }

 

QTextStream out(&file);

QListIterator <MyObject *> iter( myObjets);

whilte(iter.hastNext() {

   mo = iter.next();

   out << mo->field1 << "," << mo->field2 << "," .... << "\n";

}

file->close();

 

 

I not sure how to send it as an attachment. You can search for that on this forum as it is a common question.  Myself I could never get sending attachment to work the way I wanted to so gave up.  And decided the user can just send file as an attachment if they want to.

 

Hope this is of some value.

 

 

Developer
Posts: 134
Registered: ‎01-25-2010
My Device: Z30, Z10, Q10, Dev Alpha B & Bold 9900
My Carrier: Bell

Re: Creating a csv files, then sending file has an attachment ...

Thanks for the tip... I got it working :smileyhappy: For initiale release will go with the export function.