×

Discussion Board

Results 1 to 10 of 10
  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    26

    Create new file to write each new SMS's content

    Hi All,

    I am new to Symbian and this happens to be my first post..

    I am developing a messaging app which listens to incoming SMS and as soon as new SMS arrives I need to extract the content of the SMS and write it to a file. For this I need to create a new file each time I have a new SMS with dynamic file names..

    Can you please help me with my WriteToFile().. at the moment i am simply replacing the file existing with a new file with same name and writing the content of the SMS.. But how can I create new file each time I get a new sms with say incrementing name..

    void CSMSEngine::WriteToFile(const TPtrC8& aSMSContent8)
    {

    RFs fs;
    User::LeaveIfError(iFs.Connect());
    RFile file;
    User::LeaveIfError(file.Replace(iFs, KFileSpec, EFileWrite));
    User::LeaveIfError(file.Write(aSMSContent8, aSMSContent8.Length()));
    file.Close();
    fs.close;
    //File closed


    }

    Can u plz post me any suggestions r examples of such operation..

    Thank You..

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Budapest, Hungary
    Posts
    28,752

    Re: Create new file to write each new SMS's content

    You could use the TMsvId somewhere in the filename.
    Code:
    _LIT(KFileNameFormat,"e:\\SMS[%08X].txt");
    TFileName filename;
    filename.Format(KFileNameFormat,msvid);

  3. #3
    Registered User
    Join Date
    Sep 2010
    Posts
    26

    Re: Create new file to write each new SMS's content

    Thanks for the quick reply wizard_hu..

    I am actually listening for SMS using sockets and not on a standard SMS handler api.. to be honest i am not sure where to look for the senders details in my RunL().. can u plz guide how I can retreive senders information in the following code sot hat use it as the KFileNameFormat as mentioned by you..

    my RunL() code:

    void CSMSEngine::RunL()
    {
    if(iRead)
    {
    CSmsBuffer *smsBuffer = CSmsBuffer::NewL();
    CleanupStack::PushL(smsBuffer);
    //Stream that reads a CSmsMessage object across a socket.
    RSmsSocketReadStream readStream(iSocket);
    //Allocates and creates a CSmsMessage
    //ESmsDeliver-SMS-DELIVER, sent from service center to Mobile Station.
    iSmsMessage = CSmsMessage::NewL(iFs,CSmsPDU::ESmsDeliver,smsBuffer);
    //Internalises data from stream to CSmsMessage
    iSmsMessage->InternalizeL(readStream);
    readStream.Close();
    //Extracting the received message to a buffer
    iSmsMessage->Buffer().Extract(iBuf,0,iSmsMessage->Buffer().Length());
    iSocket.Ioctl( KIoctlReadMessageSucceeded,iStatus, &iPckgBuf, KSolSmsProv);
    //Printing the received Message.
    CAknInformationNote* note122=new(ELeave) CAknInformationNote;
    note122->ExecuteLD(iBuf);
    HBufC8* SMSContent8 = HBufC8::NewL(iBuf.Length());
    CleanupStack::PushL(SMSContent8);
    SMSContent8->Des().Copy(iBuf);
    WriteToFile(SMSContent8->Des()); // Write SMS Body in the SMSBody.txt file
    CleanupStack::PopAndDestroy(SMSContent8);

    iRead=EFalse;
    SetActive();

    CleanupStack::PopAndDestroy(smsBuffer);


    }
    This is the first time i am using this listening for sms using sockets so i am honestly not sure how i can retreive the senders details like name or number or time.. Plz guide me..

    Thanks a lot..

  4. #4
    Nokia Developer Champion
    Join Date
    Mar 2006
    Location
    Helsinki, Finland
    Posts
    8,347

    Re: Create new file to write each new SMS's content

    You can retrieve the sender's number as follows:
    Code:
    ....
    iSmsMessage->Buffer().Extract(iBuf,0,iSmsMessage->Buffer().Length());
    TBuf<20> from;
    from.Copy(iSmsMessage->ToFromAddress());
    ...
    ...
    ...
    Last edited by kiran10182; 2010-09-15 at 12:06.
    Nokia Developer Wiki Moderation team

  5. #5
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Budapest, Hungary
    Posts
    28,752

    Re: Create new file to write each new SMS's content

    Since a single sender can send multiple messages to you, this approach might have problems. You may consider creating some custom numbering approach (and store the number in some setting file, so the numbering will not restart with your code).
    A quick and dirty alternative is to use RFile::Temp.

  6. #6
    Registered User
    Join Date
    Sep 2010
    Posts
    26

    Re: Create new file to write each new SMS's content

    Personally i want to take this opportunity to Thank you guys wizard_hu and Kiran whole heartedly..

    I have checked your contributions in so many discussions related to general and messaging domains.. in fact it helped me a lot in starting development for Symbian and developing my current app related to messaging..

    I have used kiran's idea of extracting the sender's address from iSmsMessage and using RFile::Temp creating seperate files for each sms entry as suggested by wizard_hu..

    void CSMSEngine::WriteToFile(const TPtrC8& aSMSContent8, const TPtrC& areceipientNumber)
    {
    _LIT(KFileSpec, "C:\\Data\\In\\");
    _LIT(KSMS,".txt");
    TFileName filename; ;
    filename.Append(areceipientNumber);
    filename.Append(KSMS);
    RFile file;
    User::LeaveIfError(file.Temp(iFs,KFileSpec,filename,EFileWrite));
    //User::LeaveIfError(file.Create(iFs, filename, EFileWrite));
    User::LeaveIfError(file.Write(aSMSContent8,aSMSContent8.Length()));
    User::InfoPrint(_L("Written"));
    file.Close();
    //File closed

    }

    the code is creating Tem files with random names i guess like TMP740b4.$$$ , TMP750e9.$$$ etc.. I am trying to append filename (areceipientNumber) + extension (.txt) to make my file name meaningfull.. but is there anything wrong in the way i am appending the areceipientNumber followed by .txt extension because the code is only creating temp names n not files with name intended by me through filename append..

    Can we create Temp files with filename and extension provided by us..?

    Thanks Once again..

  7. #7
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Budapest, Hungary
    Posts
    28,752

    Re: Create new file to write each new SMS's content

    RFile has methods Name and Rename, so you can try doing some magic, adding some prefix and extension.
    However a good question is if it also affects uniqueness. If RFile::Temp gives you a name "TMP0000", it is unique. However if you rename this file to "MySMSFromJohnTMP00000.txt", RFile::Temp may find TMP00000 unique again. So, it may require some experimentation, and it is probably safer not renaming the files.

  8. #8
    Registered User
    Join Date
    Sep 2010
    Posts
    26

    Re: Create new file to write each new SMS's content

    Thanks wizard_hu..

    As if now I am using RFile::Temp to create temp files for each new sms entry..and it is working fine.. As suggested by you I am trying to work on RFile name and rename and other examples to create file names with meaningfull names and extensions..

    Thanks..

  9. #9
    Registered User
    Join Date
    Feb 2007
    Posts
    17

    Re: Create new file to write each new SMS's content

    Hi

    It has been long time since i got back to this forum. I am surprised to see none correcting the newbie programmer about the naming convention ( Trailing L in his leaving function) or about using Cleanupstack (file reference).
    If i am not wrong, 4 years ago such post was replied with some good articles to read up and some nice urls added to get to know the fundamentals along with his issue solved.

    Jinesh

  10. #10
    Nokia Developer Champion
    Join Date
    Mar 2006
    Location
    Helsinki, Finland
    Posts
    8,347

    Re: Create new file to write each new SMS's content

    Quote Originally Posted by JineshKrishnan View Post
    Hi

    It has been long time since i got back to this forum. I am surprised to see none correcting the newbie programmer about the naming convention ( Trailing L in his leaving function) or about using Cleanupstack (file reference).
    If i am not wrong, 4 years ago such post was replied with some good articles to read up and some nice urls added to get to know the fundamentals along with his issue solved.

    Jinesh
    You are more than welcome to suggest such conventions and cleanupstack idioms. I wish I would see you more often than coming back again after 4 years so that people will benefit from your regular contribution.
    Nokia Developer Wiki Moderation team

Similar Threads

  1. Create new content ==> "Permission denied. ..." ?
    By KyleMLee in forum [Closed] Publishing to Nokia Store
    Replies: 0
    Last Post: 2010-06-24, 04:32
  2. Replies: 6
    Last Post: 2006-10-31, 05:20
  3. Metrowerks CW - Create New .cpp File?
    By glmuelle in forum Symbian Tools & SDKs
    Replies: 15
    Last Post: 2006-10-19, 19:51
  4. Replies: 3
    Last Post: 2006-10-09, 12:24
  5. How to copy a file's content to a new file?
    By ruixj in forum Symbian Tools & SDKs
    Replies: 3
    Last Post: 2004-04-05, 08:45

Posting Permissions

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