Hi all . I m trying to read contents of a file using streamreader classs of c#.net which is a result of data transferred over the network. it contains some transmission syymbol eg. eot,can,soh etc.
Beacuse of that it is showing square symbols.

Kindly arrangea code to read the file contents in a proper way.


7 Years
Discussion Span
Last Post by skg123

>to read the file contents in a proper way.

It depends upon the encoding (UTF8, Unicode, ANSI).

StreamReader reader = new StreamReader("file", Encoding.UTF8, true)

Show us the code you have so far and we will advise on changes you can make.

contents of my file in notepad are like below:

00277XTK>y  .<        ™  Nò   , +       JTK(,    ,       
,        ,       ö+       â+       2,       P,       d,       -       ,-          M@     @U@  ¶*  , ,- è*                           ™  æ  ê  Ë  ê      ï   dT &    ÒuQñA

My code in C# is like below:

string nn = " ";
            StreamReader sr = new StreamReader("WriteDatadepak.dat",Encoding.ASCII,true);
            string ss = sr.ReadToEnd();//.Trim();
            int l1 = ss.Length;
            int ff;
            for (int n = 0; n < l1; n++)
                ff = Convert.ToInt16(ss[n]);

                nn = nn + ss[n];

           textBox1.Text = nn;

result of this code in text box is like this:

00277XTK>y  .<        ?  N?   , +       JTK(,    ,       
,        ,       ?+       ?+       2,       P,       d,       -       ,-          M@     @U@  ?*  , ,- ?*                           ?  ?  ?  ?  ?      ?   dT &    ?uQ?A

Pls let me have a c# code to read the contents of .dat binary file in a correct way.

Thanks in Adv.

Edited by __avd: Added [code] tags. Encase your code in: [code] and [/code] tags.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.