PDA

View Full Version : finding text files in C# console applications


BobLewiston
01-18-2009, 08:35 PM
In C# console applications, isn't there a simpler way than handling exceptions to just find out if a text file of a given name exists in the current directory? I'm talking about something along the same lines as the following methods:

create text file:
StreamWriter SW;
SW = File.CreateText ("MyFile.txt");
open existing text file:
StreamReader SR;
SR = File.OpenText ("MyFile.txt");
append to text file:
StreamWriter SW;
SW = File.AppendText ("MyFile.txt");

oracleguy
01-18-2009, 09:15 PM
Yes, use the File.Exists() method to find out if a file exists or not.