Here is the code to read a text file from disk one line at a time into a string. This code ensures the file exists and properly closes the file if an exception occurs.
using System;
using System.IO;
namespace CSharp
{
class Program
{
static void Main( string[] args )
{
string filePath = @"c:\temp\test.txt";
string line;
if (File.Exists( filePath ))
{
StreamReader file = null;
try
{
file = new StreamReader( filePath );
while ((line = file.ReadLine()) != null)
{
Console.WriteLine( line );
}
}
finally
{
if (file != null)
file.Close();
}
}
Console.ReadLine();
}
}
}
Subscribe to:
Post Comments (Atom)
Ajax CalendarExtender displaying at wrong position in Chrome
< script type ="text/javascript" language ="javascript"> function onCalendarShown(sender, args)...
-
Suppose FieldName is the Bit field which tells whether the link should be visible true or false so design your gridview template like th...
-
There is no direct way to Expand/Collapse all panes in Accordion Extender. Using following java script, Accordion can be Expand/Collaps...
-
< script type ="text/javascript" language ="javascript"> function onCalendarShown(sender, args)...
No comments:
Post a Comment