locked
Creating a text file writing to it and deleting it.

    Question

  • I am a new to C# and programming. I made a WPF application.

    And I was able to do such things, I mean creating file in any directory of hard-drive. writing text to it and sometimes deleting it. But I don't know how to do these in an windows 8 applications. Please help me out.

    I have tried this code:

    using (StreamReader sr = new StreamReader(fname.Text)) { StringBuilder data = new StringBuilder(); while ((line = sr.ReadLine()) != null) {

    char[] buf = new char[200];

    /*..........Doing some process........*/ string putline = new string(buf) data.AppendLine(); data.Append(putline); }

    StreamWriter outfile;
            using (outfile = new StreamWriter(filename))
           {
           outfile.Write(data);
            }

    }

    /* For deleting I used this chunk of code actually I am deleting the file

    from which I read data.*/

            if (System.IO.File.Exists(fname.Text))
            {
    System.IO.File.Delete(fname.Text);
            }

    where fname is a textbox which contains the address of file to be read and filename is the file to which data should be written.
    Sunday, April 19, 2015 12:55 PM

Answers

  • Hi Madhusoodan,

    >> I mean creating file in any directory of hard-drive. writing text to it and sometimes deleting it. But I don't know how to do these in an windows 8 applications. Please help me out.

    In Windows 8 app, we can refer to the following article about how to create/read/write a file:
    https://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh758325.aspx .

    For how to delete file, please try to use the StorageFile.DeleteAsync method in Windows 8 app.

    Best Regards,
    Amy Peng

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, April 20, 2015 10:02 AM
    Moderator