Encoding Question - print £ in c#

I have text file that I need to ingest.  It contains a sterling sign £.
When I try to print it gets converted to something else.

When writing to the file using streamwrite I tried encoding.default which displays the £ as a ?
When using UTF8 Textpad can't open it.  When I use notepad it shows another weird character.
How can I print a £?
I'm using C# with .NET framework 3.5.
This is a windows rather than a web form.
AlHal2Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
you need to save the text file as utf-8 encoding compatible.

Ref:
StreamWriter Constructor (Stream, Encoding, Int32)
https://msdn.microsoft.com/en-us/library/72d9f8d5%28v=vs.110%29.aspx
AlHal2Author Commented:
I'm using the syntax below and am getting the message that the text file contains characters that do not exist in the code page 1252 (ANSI - :LATIN I).  They will be converted to the system default character, if you click OK.
Sure enough the £ gets converted to a ?

StreamWriter sWriter = new StreamWriter(s_m_log_file_name,false,System .Text .Encoding.UTF8,512  );
        IEnumerator itor = v_p_m_messages.GetEnumerator();

        while (itor.MoveNext())
        {
            sWriter.WriteLine(itor.Current.ToString());
        }
        sWriter.Close();

Open in new window

AlHal2Author Commented:
When I save the input file as UTF8 I get an extra  next to the £
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

AlHal2Author Commented:
However the output file comes out OK!
is this what you would expect?
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
yes, this is the exactly what I mentioned.

>>StreamWriter sWriter = new StreamWriter(s_m_log_file_name,false,System.Text.Encoding.UTF8,512  );

I tested locally, it works for me as well.
private void button1_Click(object sender, EventArgs e)
        {
            string fileName = txtPath.Text + "\\test.txt";
            string textToAdd = txtContent.Text;
            FileStream fs = null;
            try
            {
                if (System.IO.File.Exists(fileName))
                {
                    System.IO.File.Delete(fileName);
                }
                fs = new FileStream(fileName, FileMode.CreateNew);
                using (StreamWriter writer = new StreamWriter(fs, Encoding.UTF8, 512))
                {
                    writer.Write(textToAdd);
                }
                MessageBox.Show("Done!", "ok", MessageBoxButtons.OK);
            }
            finally
            {
                if (fs != null)
                    fs.Dispose();
            }
        }

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AlHal2Author Commented:
Thanks.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.