Hi I have some code to re-encode uniface text files in to ANSII for use by a 3rd party application.

This code works fine if I create a new text file using notepad, save it as Unicode and run my script. I get a lovely output file in ANSII.

When i use an actual output file from our general ledger, the script runs & writes out the file, but the output is still showing as unicode.. Could anyone shed any light on what might be going on here??

Here is my script:

foreach (FileInfo file in files)
            {
                filename = file.Name.ToString();
                destinationpath = dest + "ARI" + i + ".dat";
                i++;
                StreamReader fileStream = new StreamReader(file.FullName);
                string fileContent = fileStream.ReadToEnd();
                fileStream.Close();
                StreamWriter ansiWriter = new StreamWriter(destinationpath, false, Encoding.GetEncoding(1250));
                ansiWriter.Write(fileContent);
                ansiWriter.Close();
            }

Many thanks!!

Recommended Answers

All 5 Replies

Do you mean ASCII? Code page 1250 is Central European, which is still unicode. If you really mean ASCII, you want to change line 9 to Encoding.ASCIIEncoding . ANSI is a standards setting organization, and there is no ANSII.

thanks for your reply - I have made the change but, still i am getting output in Unicode :-(

This is the script now:

foreach (FileInfo file in files)
            {

                filename = file.Name.ToString();
                destinationpath = dest + "Benefits" + i + ".dat";
                i++;
                StreamReader fileStream = new StreamReader(file.FullName);
                string fileContent = fileStream.ReadToEnd();
                fileStream.Close();
                StreamWriter ansiWriter = new StreamWriter(destinationpath, false, Encoding.ASCII);
                ansiWriter.Write(fileContent);
                ansiWriter.Close();
            }

I added a breakpoint to make 100% sure that this bit of code is being run when i execute the program & sure enough it runs through & executes the line that clearly states output in ASCII!!

I have had another think about this and want to clarify the actions I need to replicate in code to see if anyone can think of another way of working this..

We produce a file from SAP - it comes out in unicode. We then have to open this file in notepad and change the encoding from unicode to ANSI. we then save the file to hold that change. We then run that file in to our third party application. What ever the change notepad makes when the encoding type is changed is what I need to replicate in code.

Can anyone help with that??

Many thanks

                CultureInfo culture = new CultureInfo("el-GR");
                int codePage = culture.TextInfo.ANSICodePage;
                Encoding GreekEncoding = Encoding.GetEncoding(codePage);

then at this line :
                new StreamWriter(destinationpath, false, GreekEncoding);

CultureInfo culture = new CultureInfo("Ar-SA");
int codePage = culture.TextInfo.ANSICodePage;
Encoding ANSIEncoding = Encoding.GetEncoding(codePage);
//using in creating file
StreamWriter SW = new StreamWriter(filename, false, ANSIEncoding);

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.