Quantcast
Channel: Windows Forms General forum
Viewing all articles
Browse latest Browse all 12583

Write output to text file - Append or Overwrite confirmation at runtime

$
0
0

Hi,

I am working on a .NET windows application.

Program writes output data to text files. Following code is used to write Data to text files.

I want to check if the output file with the same name already exists. If exists, want to get confirmation from user whether to append or overwrite.

FileStream fsTXT;
StreamWriter rsTXT;
string OutputFilename = OutputDir + "\\" +  txtFileName.Text + ".txt";
fsTXT = new FileStream(OutputFilename, FileMode.Append, FileAccess.Write);
rsTXT = new StreamWriter(fsTXT);
//program stores output data in outputrecord string 
rsTXT.WriteLine(outputrecord);   //write the output

I want to change the FileMode.Append parameter at runtime based on the user confirmation. Whether to Append to existing file or Overwrite it?

How to change the FileMode.Append parameter in fsTXT = new FileStream(OutputFilename, FileMode.Append, FileAccess.Write) at runtime based on the confirmation from the user.

Thanks

Ashok


Viewing all articles
Browse latest Browse all 12583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>