SaveFileDialog.ShowDialog() returns Cancel when Yes to overwrite ...

J

Joe Duchtel

Hello -

I have the following code to detemine a file name when my application
is saving a file. The problem is that if the file already exists and
I select the Yes button in the "Do you want to replace" dialog, the
DialogResult is Cancel instead of OK. Is there something I am
missing?

Dim lSaveFileDialog As New SaveFileDialog

lSaveFileDialog.AddExtension = True
lSaveFileDialog.Filter = "PNG (*.png)|*.png"
lSaveFileDialog.InitialDirectory = lDefaultPath
lSaveFileDialog.OverwritePrompt = True
lSaveFileDialog.Title = "Save As"

Dim lDialogResult As DialogResult = lSaveFileDialog.ShowDialog()

Thanks,
Joe
 
J

Joe Duchtel

Hello -

Yep ... I also used the desktop as lDefaultPath but it will just not
work. I have .NET 2.0 installed. Maybe that is the problem?
The workaround I found is to just disable the overwrite prompt
(OverwritePrompt = True) and then to a File.Exists() myself to prompt
for the overwrite. The MsgBox() looks the same to the user will not
notice ... oh well ...

Thanks!
Joe
 
K

kimiraikkonen

Hello -

Yep ... I also used the desktop as lDefaultPath but it will just not
work. I have .NET 2.0 installed. Maybe that is the problem?
The workaround I found is to just disable the overwrite prompt
(OverwritePrompt = True) and then to a File.Exists() myself to prompt
for the overwrite. The MsgBox() looks the same to the user will not
notice ... oh well ...

Thanks!
Joe

Hi Joe,
Just tried your code using .NET 2.0 on VB 2005 express:

First, IDefaultPath variable gives "not declared" error as well then i
put a MsgBox to determine which result is returned at the end of code
as follows:

Dim lSaveFileDialog As New SaveFileDialog

lSaveFileDialog.AddExtension = True
lSaveFileDialog.Filter = "PNG (*.png)|*.png"

lSaveFileDialog.OverwritePrompt = True
lSaveFileDialog.Title = "Save As"

Dim lDialogResult As DialogResult =
lSaveFileDialog.ShowDialog()

MsgBox(lDialogResult.ToString)

and when i confirm to overwrite, Msgbox displays result as "OK".

Anyway, i couldn't understand the logic of your code well, but why
don't you just place SaveFileDialog control on your form if you're not
instantiating it at runtime and if your intention to determine the
dialog result, with more plain code like:

If SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
' Returns OK result
MsgBox("OK Clicked")
ElseIf SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.No Then
' Returns No result
MsgBox("No Clicked")
' ... goes on...
End If


Thanks,

Onur Güzel
 
J

Joe Duchtel

Hello -

Sorry ... I forgot to take the lDefaultPath out of the code snippet I
posted. So it did work with .NET 2.0 and 2005? I actually just
noticed that I am using .NET 1.1 since I have Visual Studio 2003. I
do have 2.0 installed but that cannot be integrated with 2003. So
maybe that is the problem?

Thanks a lot!
Joe
 
K

kimiraikkonen

Hello -

Sorry ... I forgot to take the lDefaultPath out of the code snippet I
posted.  So it did work with .NET 2.0 and 2005?  I actually just
noticed that I am using .NET 1.1 since I have Visual Studio 2003.  I
do have 2.0 installed but that cannot be integrated with 2003.  So
maybe that is the problem?

Thanks a lot!
Joe














- Show quoted text -

I haven't used .NET 1.1 or 2003 ever. I tested using .NET 2.0 with VB
2005 express and OK result is returned after overwrite confirmation.
It may not be a bug in SaveFileDialog class as i hope even in 2003,
but worth to try with 2005 at least and you can see if it solves.

And it'll make things more clear to state what your real goal is with
SaveFileDialog.

Thanks,

Onur Güzel
 
J

Joe Duchtel

Hello -

I am using the SaveFileDialog out of a *.exe that does not have a GUI
frontend. It is just something quick to run to convert files and
needed to prompt the user for a name and location under which to save
something.

Thanks,
Joe
 
J

Joe Duchtel

Hello -

Wow ... so I found a bug!

I tried the workaround but even when calling the ShowDialog() from a
function that is called from Main(), it did not work properly. So I
will stick with my own overwrite protection for now.

Thanks a lot!
Joe
 

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