string file = "text.txt"; System.IO.FileInfo fileInf = new System.IO.FileInfo(file); int buffLength = 2048; byte[] buff = new byte[buffLength]; int contentLen; // Opens a file stream to read the file System.IO.FileStream fs = fileInf.OpenRead(); try { contentLen = fs.Read(buff, 0, buffLength); // Till Stream content ends while (contentLen != 0) { System.Console.WriteLine(buff); contentLen = fs.Read(buff, 0, buffLength); } } catch (System.Exception ex) { System.Console.WriteLine(ex.Message); } finally { fs.Close(); }
System.Exception ex; string ex.Message; //descriptive text of the error System.Collection.IDictionary ex.Data; string ex.Source; //the name of class or object that caused error