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.

Thanks

Recommended Answers

All 3 Replies

>to read the file contents in a proper way.

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

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.

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

hi,
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.

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.