WriteAllText Question

Hi All,

Why does

My.Computer.FileSystem.WriteAllText

create a i at the start of a file

And is there a way to stop it doing this

The output of the program (created by WriteAllText) is dependant on a # starting the file, and not a i #

Obviously, it's fairly easy to write the code to read the above, rather than just the # but it's a bit annoying.

btw, this doesn't appear when viewed in textpad/notepad etc, only Excel.

cheers in advance.

James


Answer this question

WriteAllText Question

  • qrli

    Because the default encoding of the text file is UTF8.

    To indicate the encoding of the file, a few extra bytes are added to the start of the file which are used by the program opening the file to display the contents correctly.

    If you pass an Encoding object to one of the WriteAllText overloads, you can change the encoding it is written:


    WriteAllText("c:\test\mytextfile.txt", "Test", false, System.Text.Encoding.ASCII)
     


  • Saeedsad

    duh!

    should have thought of that.

    thanks though. worked a treat.

  • WriteAllText Question