satheesh
satheesh

Reputation: 197

How to read, write in file windows mobile 6.5

in windows mobile 6.5 how read/write text in a file

Upvotes: 0

Views: 4644

Answers (2)

Rosemol Francis
Rosemol Francis

Reputation: 25

To write to a file

        FileInfo fi = new FileInfo(Path+"\\txtServer.inf");//\\Application
        using (TextWriter txtWriter = new StreamWriter(fi.Open(FileMode.Truncate)))
        {
            txtWriter.WriteLine("Hello");

        }

To read from file

    string path = Path + "\\txtServer.inf";//\\Application

    if (!File.Exists(path))
        {
            using (StreamWriter sw = File.CreateText(path))
            {

            }
        }
        else
        {
            using (StreamReader sr = File.OpenText(path))
            {
                string s = "";
               Label1.Text ="";

                while ((s = sr.ReadLine()) != null)
                {
                     Label1.Text = s;
                 }
             }
         }

Upvotes: 0

satheesh
satheesh

Reputation: 197

windows mobile 6.5 how write/read text in a file insert a label(label1) in design view add the following lines in your code


Code:

        string path = "\\test.txt";//file Loc: *start->file explorer->text.txt*
        if (!File.Exists(path))
        {
            using (StreamWriter sw = File.CreateText(path))
            {
                sw.WriteLine("Hello");
                sw.WriteLine("And");
                sw.WriteLine("Welcome");
            }
        }
        using (StreamReader sr = File.OpenText(path))
        {
            string s = "";

            label1.Text = "";
            while ((s = sr.ReadLine()) != null)
            {
                label1.Text += s;
            }
        }

Upvotes: 3

Related Questions