Write to textfile in ANSI format

  • Thread starter Thread starter Thomas A
  • Start date Start date
T

Thomas A

Hi,

I write a string value to a textfile , if the string dont contains swedish
Å,Ä and Ö , the file will be written in ANSI.

So far so god but....

If the string contains Å or Ä or Ö ,the file will be written in UTF-8.

Thats not good, have anyone a tips for me so it always will be written in
ANSI.

My code is now:

'The Outstring contains my string to write into my file

Dim OutPath as string = "c:\test.txt"
Dim mySW As StreamWriter

mySW = File.CreateText(OutPath)

' Debug.Write(mySW.Encoding)
mySW.Write(Outstring)
mySW.Close()
mySW.Flush()


//Thomas
 
Thomas A said:
Hi,

I write a string value to a textfile , if the string dont contains
swedish Å,Ä and Ö , the file will be written in ANSI.

So far so god but....

If the string contains Å or Ä or Ö ,the file will be written in
UTF-8.

Thats not good, have anyone a tips for me so it always will be
written in ANSI.

My code is now:

'The Outstring contains my string to write into my file

Dim OutPath as string = "c:\test.txt"
Dim mySW As StreamWriter

mySW = File.CreateText(OutPath)

' Debug.Write(mySW.Encoding)
mySW.Write(Outstring)
mySW.Close()
mySW.Flush()


//Thomas

dim fs as filestream
fs = new filestream(outpath, ...)

mysw = new streamwriter(fs, System.Text.Encoding.Default)
 
Back
Top