Tech Off Thread

4 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

C# (Mobile): Saving a text file?

Back to Forum: Tech Off
  • User profile image
    SlackmasterK

    Seems like a relatively straightforward task:  I want to save a string to a text file.  Normally I'd use System.IO.File.WriteAllText, but I'm developing an app for a Windows Mobile 5 device.  System.IO.File doesn't seem to contain a WriteAllText object in the .NET Compact Framework.  Is there a workaround that doesn't involve complicated byte arrays and streamwriters?

  • User profile image
    Sven Groot

    StreamWriters aren't complicated.

    using( System.IO.StreamWriter writer = new System.IO.StreamWriter("foo.txt") )
    {
       writer.Write("Your text here!");
    }

    That works fine on the .Net CF.

  • User profile image
    Yggdrasil

    Sven Groot wrote:
    StreamWriters aren't complicated.

    using( System.IO.StreamWriter writer = new System.IO.StreamWriter("foo.txt") )
    {
       writer.Write("Your text here!");
    }

    That works fine on the .Net CF.


    I still find myself using StreamReader/Writers when I need to read/write a file, before remembering this newfangled 2.0 WriteAllText whatchamacallit.

    It's a shame I got used to it, since WriteAllText is so AMAZINGLY convenient.

  • User profile image
    littleguru

    I didn't even notice this method so far... Still stuck with the streamwriters and streamreaders...

    But it's a nice to know!

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.