Where are you setting the encoding for your StreamReader, sr
? If you are not doing this explicitly, and if you are setting the encoding of the StreamWriter before you perform any reads of your file(my best guess), then the CurrentEncoding
of the StreamReader may change (it autodetects from the source file).
From MSDN on StreamReader.CurrentEncoding
The current character encoding used by the current reader. The value can be different after the first call to any Read method of StreamReader, since encoding autodetection is not done until the first call to a Read method.
To determine the encoding you can read off the first line of the file with the StreamReader and then do :
sw = New IO.StreamWriter(NewFilepath, False, sr.CurrentEncoding)