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



On Jun 5, 4:49 am, Joe Duchtel <duch...@xxxxxxxxx> wrote:
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

On Jun 4, 12:43 pm, "Patrice" <http://www.chez.com/scribe/> wrote:

Works fine here using the desktop as lDefaultPath and a .htm file.

I'm using 3.5...

Either :
- some other condition that causes Cancel to be returned (locked file ? non
writable location ?)
- a bug in your version of the framework
- a bug in your own code that makes the return value looks bad when it is
actually good

Good luck.

--
Patrice

"Joe Duchtel" <duch...@xxxxxxxxx> a écrit dans le message de groupe de
discussion :
2dd9a2af-2096-4118-b71e-cbbce552e...@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

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- Hide quoted text -

- Show quoted text -

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

.