I am having problems creating a file from the result of a
XslTransform.Transform operation. This is XML->EDI conversion and the
resulting text has to be in ASCII format, but no matter what I do the
output of the file is in UTF-8.
Please note: I'm using .NET Framework 1.0.
Here is the code that I have been attempting to use:
public void Test()
{
string templateFullPath = @"c:\_bin\temp\test.xsl";
string outputFile = @"c:\_bin\temp\output4.txt";
string inputFile = @"c:\_bin\temp\test.xml";
Encoding encoding = System.Text.Encoding.ASCII;
StreamWriter sw = new StreamWriter(outputFile,false,encoding);
XmlDocument doc = new XmlDocument();
doc.Load(inputFile);
XslTransform template = new XslTransform();
template.Load(templateFullPath);
template.Transform(doc,null,sw);
Console.WriteLine(sw.Encoding.ToString());
sw.Flush();
sw.Close();
string encodingName = DetermineFileType(outputFile);
Console.WriteLine("text file encoding = " + encodingName);
}
public string DetermineFileType(string aFileName)
{
string sEncoding = string.Empty;
StreamReader oSR = new StreamReader(aFileName, true);
oSR.ReadToEnd();
sEncoding = oSR.CurrentEncoding.EncodingName;
return sEncoding;
}
The output of the transformation is supposed to be a single line with
header information and multiple lines with "item" data separated by
hard returns.
The really strange thing is that the first WriteLine (querying the
encoding of the streamwriter shows ASCII), but the second one shows
UTF-8. I would doubt the DetermineFileType results, but when I try to
open the file in notepad (or other text editors) the output is one
long line of text with a little box where the hard return should be.
What am I doing wrong?
Thanks in advance.