1

Visual Studio 2015 - Visual C# - Windows Forms - .NET Framework 4.6.1

Hi im trying to write new line in a .txt file stored on Properties.Resources

I tried the following:

File.AppendAllText(Properties.Resources.myTXTfile, "LALALA" + Environment.NewLine);

And this other one:

using (var writer = new StreamWriter(Properties.Resources.myTXTfile)) { writer.WriteLine("LALALA"); }

but doesn't changes anything to my file

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
  • Have you tried File.AppendAllText(Properties.Resources.myTXTfile, "L\nA\nL\nALA" + Environment.NewLine); and read what contains – Marco Luongo Feb 10 '17 at 14:55

2 Answers2

0

writer.WriteLine adds a NewLine at the end automatically. So the results are the same. writer.Write does the same without line breaks.

Booser
  • 576
  • 2
  • 9
  • 25
0

try

var c = new StreamWriter(Properties.Resources.myTXTfile, true);
c.AutoFlush = true;
c.WriteLine("LALALA");
c.Dispose();

Or

using (StreamWriter c = new StreamWriter(Properties.Resources.myTXTfile, true))
{
    c.WriteLine("LALALA");
}

Because when you use object in using statement, it calls Dispose method and in the case of StreamWriter it call Fush on object as well which causes data to be written in file.

True parameter within StreamWriter to append text if file exists, if not a new file will be created

Mhd
  • 2,778
  • 5
  • 22
  • 59