Good day,
I started to program c# some days ago and I´m having difficulty to read a text file.

I wrote the code below to read the following line of a text file:

AdmPassword=�‘“•—™

All caracters of the password have decimal values between 128 and 255.
The problem is . . . when I run the program, it give to me the following string:

AdmPassword=������

Someone know what I have to do to program read the file correctly?
Thankyou.

private void abrirToolStripMenuItem_Click(object sender, EventArgs e)
{
    string strAuxiliar = " ";

    /* Abre o Arquivo */
    if(openFileDialog1.ShowDialog() == DialogResult.OK)
    {
        System.IO.StreamReader LeitorDoArquivo = new 
        System.IO.StreamReader(openFileDialog1.FileName);

        /* Lê a Linha do Arquivo */
        strAuxiliar = LeitorDoArquivo.ReadLine();
    }
}

Recommended Answers

All 3 Replies

I can't find any problem in that except you forgot to close it. However, when I copy your text to notepad and save it. It asks me that if I save it as ANSI it will lost data because your text isn't in ANSI. If I save it in Unicode mode. It's alright. Try it.

Perhaps use a BinaryReader?

I tested it already. StreamReader is alright. Just make sure to save it as Unicode. I think when you input the data it lost already. Are u enter the information by notepad?

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.