GIDForums  

Go Back   GIDForums > Computer Programming Forums > .NET Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 18-Jan-2009, 12:43
BobLewiston BobLewiston is offline
Junior Member
 
Join Date: Nov 2008
Posts: 53
BobLewiston is on a distinguished road

Finding text files in C# console applications


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:
C-SHARP / C# Code:
StreamWriter SW = File.CreateText ("MyFile.txt");
open existing text file:
C-SHARP / C# Code:
StreamReader SR = File.OpenText ("MyFile.txt");
append to text file:
C-SHARP / C# Code:
StreamWriter SW  = File.AppendText ("MyFile.txt");
Last edited by admin : 19-Jan-2009 at 00:06. Reason: Please insert your example C# codes between [CSHARP] and [/CSHARP] tags
  #2  
Old 06-Apr-2009, 06:03
erniegerdie erniegerdie is offline
Awaiting Email Confirmation
 
Join Date: Feb 2004
Location: England
Posts: 93
erniegerdie has a spectacular aura abouterniegerdie has a spectacular aura about

Re: Finding text files in C# console applications


Use File.Exists

to produce something like...

C-SHARP / C# Code:
StreamWriter sw = null;
string sourceFile = "MyFile.txt";

 if (File.Exists(sourceFile))
        {
          StreamReader SR = File.OpenText (sourceFile);
...
        }
else {
          StreamWriter SW  = File.AppendText (sourceFile);
...
      }
 
 

Recent GIDBlogVista ?Widgets? on Windows XP by LocalTech

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Power Calibration Error In Nero Fix (hopefully) matt3678 Computer Hardware Forum 60 20-Aug-2009 05:04
Bloodshed Dev C++ Project Options JdS C++ Forum 6 11-Nov-2005 17:23
converting text files to html files kensenb C Programming Language 13 09-Nov-2004 11:33
CD burner wont burn!! robertli55 Computer Hardware Forum 1 18-Jun-2004 10:53
Yet another CD burner problem: Lite-On LSC-24082K Erwin Computer Hardware Forum 1 22-May-2004 11:28

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 22:02.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.