> Hello,
>
[quoted text clipped - 28 lines]
>
> Thanks
Hi,
The StreamReader uses UTF-8 encoding if not told otherwise. In addition, File.OpenText is meant for UTF-8 encoded files.
Try changing your code to something like
using(FileStream fs = File.Open(strFileName, ...))
{
using(StreamReader sr = new StreamReader(fs, Encoding.Default))
{
...
}
}
You don't have to close the StreamReader since the using statement will do it for you.

Signature
Happy coding!
Morten Wennevik [C# MVP]
Gaël Rosset - 30 May 2007 22:16 GMT
This worked :-)
Thanks for your help Morten.
public static string[] fileReadAllLines(string strFileName)
{
ArrayList content = new ArrayList();
using (FileStream fs = File.Open(strFileName,
FileMode.Open, FileAccess.Read))
{
using (StreamReader sr = new StreamReader(fs,
Encoding.Default))
{
string input;
while ((input = sr.ReadLine()) != null)
{
content.Add(input);
}
}
}
return toStringArray(content);
}
>> Hello,
>>
[quoted text clipped - 43 lines]
>
> You don't have to close the StreamReader since the using statement will do it for you.
Jon Skeet [C# MVP] - 30 May 2007 23:14 GMT
> public static string[] fileReadAllLines(string strFileName)
> {
[quoted text clipped - 15 lines]
> return toStringArray(content);
> }
Just out of interest, are you using .NET 1.1 or 2.0? 2.0 has
File.ReadAllLines(string, Encoding) which does the same thing, I
believe.

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Gaël Rosset - 31 May 2007 08:11 GMT
The code is a utility class for both .NET 2.0 and .NET CF which does not
support File.ReadAllLines() unfortunately...
>> public static string[] fileReadAllLines(string strFileName)
>> {
[quoted text clipped - 19 lines]
> File.ReadAllLines(string, Encoding) which does the same thing, I
> believe.