I'm trying to make a small tool to help some guys converting data between a SAP installation and a Axapta installation.
I get a text file i Western European (Windows) encoding (1252). They have put in some special chars to replace some Polish characters. Now it's my job to replace those special chars with the correct Polish characters.
FileStream objFile = new FileStream(FilePath, FileMode.Open, FileAccess.Read,FileShare.Read);
StreamReader objTemp = new StreamReader(objFile, Encoding.GetEncoding(1252));
FileStream objFile2 = new FileStream(FilePath + "_new", FileMode.OpenOrCreate,FileAccess.Write);
StreamWriter objTemp2 = new StreamWriter(objFile2, Encoding.GetEncoding(1252));
while ((strLineText = objTemp.ReadLine()) != null)
{
for (int i = 0; i < strOuterArray.Length; i++)
{
string[] strInnerArray = strOuterArray[i].Split(new char[]{';'});
strLineText = strLineText.Replace(strInnerArray[0], strInnerArray[1]);
}
objTemp2.WriteLine(strLineText);
}
objTemp.Close();
objTemp.Dispose();
objFile.Close();
objFile.Dispose();
objTemp2.Flush();
objTemp2.Close();
If I debug the application and set a breakpoint on the "objTemp2.WriteLine(strLineText);" line. Then I can se that the value inside the strLineText variable is perfect. The special char is replaced by the correct Polish character.
If I open the written file afterwards then I can't find the correct Polish characters. I'm working with "ś" & "Ś", both is just saved as "s" & "S" in the file.
Did I miss something or have I overlooked something very important?