Foraing characters missing when I read a Text file

Posted on 2005-05-16
Last Modified: 2012-05-05
Here it is a simply routine to load a file into a Hashtable, everything works fine, but when I use some characters in text file like ñ, á,é,í,ó,ú
these characters doesn't appear in the read strings.

I create the text file with Visual Studio.NET 2003 Pro.

Can someone help me?

LoadFromFile(Hashtable aTable, string aFileName){
                          FileInfo sesFile = new FileInfo(aFileName);
                  if (!sesFile.Exists) return false;
                  string [] data;
                  string lin;
                  StreamReader str = sesFile.OpenText();
                        while ((lin=str.ReadLine())!=null){
                              lin = lin.Trim();
                              if ((lin != "") && (lin.IndexOf(';') != 0)){
                                    data = lin.Split('=');
                                    aTable.Add(data[0].Trim(), data[1].Trim());
                  return true;

Text file:

In code you get:
String1=Len  (Missing ó)
String2=Nio  (Missing ñ)

Question by:mak730
    1 Comment
    LVL 9

    Accepted Solution

    Add an encoding parameter to the StreamReader's constructor:

    StreamReader str = new StreamReader(sesFile.OpenText(), Encoding.GetEncoding("ISO-8859-1"));

    I'm not sure exactly what encoding your file is using, so swap out "ISO-8859-1" for whatever it is.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
    Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now