overwrite dialog for streamwriter?

R

r_poetic

Hello,
I am using StreamWriter, and I want to check if the file I intend to
write to already exists and to have the choice to continue or bail
out. I know that File.Exists(name) will check whether the file
already exists. But I can't spot a built-in way to generate a dialog
for the user to continue and begin writing or to quit. I guess I
might write a specific dialog box for this....? Thanks for
suggestions.
 
I

Ignacio Machin ( .NET/ C# MVP )

Hello,
I am using StreamWriter, and I want to check if the file I intend to
write to already exists and to have the choice to continue or bail
out.  I know that File.Exists(name)  will check whether the file
already exists.  But I can't spot a built-in way to generate a dialog
for the user to continue and begin writing or to quit.  I guess I
might write a specific dialog box for this....?  Thanks for
suggestions.

Hi,

I'm not very sure of what you want. you can have a construction like:

if ( File.Exist( ...) )
if ( DialogResult.Yes == MessageBox.Show("are you sure you want to
overwrite. ...."))
{
// do it
}

Also remember that you cannot be 100% sure that the file does not
exist as it can be created between the File.Exist and when you use it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top