Saturday, August 6, 2011

How to read text from text files?

To read from text files try following code snippet:

string strFileName = "c:\Description.txt";
string str=string.Empty;
string description=string.Empty;
                if (System.IO.File.Exists(strFileName))
                  {
                        TextReader tReader = System.IO.File.OpenText(strFileName);
                        while ((str = tReader.ReadLine()) != null)
                            {
                                 description += str + "\r\n"; ;
                            }
                        tReader.Close();
                        tReader.Dispose();
                   }
                txtDescription.Text= description;

No comments:

Post a Comment