Re: SaveFileDialog Problem
Yes, its a bug that has plauged Windows forever. It does it with file names too. When ever you select anything in the dialog and try to type and chage it in the file textbox it will still retain the selected file. :(
Re: SaveFileDialog Problem
Quote:
Originally Posted by RobDog888
Yes, its a bug that has plauged Windows forever. It does it with file names too. When ever you select anything in the dialog and try to type and chage it in the file textbox it will still retain the selected file. :(
Hi Rob and thanks for the response. It looks like the SaveFileDialog or FileDialog is not inheritable. Is there any work around to this problem?
Re: SaveFileDialog Problem
That's really strange and I've never heard of that happening. I'm not sure if this will fix it but I think it will:
if SFD is your save file dialog box then:
Code:
sfd.AddExtension = True
sfd.DefaultExt = ".jpg"
sfd.SupportMultiDottedExtensions = False
I don't remember if that last one is supposed to be false or true but I think that would do it. Actually I'm only 90% sure that the addextension part is correct either lol. I'm very sure that some combination of those settings will prevent it from grabbing the extension at all in the first place from files they click on in there.
I believe the way I wrote it, the second line will set the default extension to jpg or whatever you want. Then the first line will ensure that if the user doesn't add an extension, it won't save as an extensionless file (I think this is the default anyway). And the third line will prevent it from getting saved as picture.txt.jpg but I'm not sure if it errors out or strips out the period or strips off the jpg or the txt part. I don't remember, just mess with it.
Either that or way way way way way better is to do sfd.AddExtension = False and sfd.SupportMultiDottedExtensions = False and then the dialog box returns the file path string they want sometimes with and sometimes without an extension. So then check if there's a period in the entire string at all. If there is, remove the extension. The best way to do this is to reverse the string and start from the last character which would now be first character and search for the index of the first period then first slash and if the slash is after the period, remove the period and every character before it. If the period is after the slash, they have a folder name with a period in it or something crazy like that. Then re-reverse it. That just stripped off the period and file extension that you'd get as a result of them clicking on a file. Then append the filepath string to end in whatever extension you want like
sfd.FilePath &= ".jpg"
actually it might not like that. You might have to store it in a string variable first.
Re: SaveFileDialog Problem
Hi Desolator144, actually I found a lot about this problem on the net and it shows that this is a well known bug in windows. Unfortunately setting all the properties you showed doesn’t solve the problem. Fortunately the dialog box’s OK event handler has a Cancel property that I will see if I can use it. If this property prevents the SaveFileDialog box to close than I may be able to show my own Overwrite Prompt and change the extension manually.
Re: SaveFileDialog Problem
I found a work around about this bug using the Cancel property of the FileOk event handler argument. Here is the code in the event; you must set the “OverwritePromt” property of the SaveFileDialog box to False.
vb Code:
Private Sub SaveFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles SaveFileDialog1.FileOk
Dim fileName As String = Me.SaveFileDialog1.FileName
Dim ext As string
Select Case Me.SaveFileDialog1.FilterIndex
Case 1
ext = "png"
Case 2
ext = "jpeg"
Case 3
ext = "bmp"
Case 4
ext = "gif"
Case 5
ext = "tiff"
Case 6
ext = "emf"
Case 7
ext = "wmf"
End Select
fileName = IO.Path.ChangeExtension(fileName, ext )
Me.SaveFileDialog1.FileName = fileName
If IO.File.Exists(fileName) Then
If MessageBox.Show("File " & fileName & " already exists." & Environment.NewLine & _
"Do you want to replace it?", Me.SaveFileDialog1.Title, MessageBoxButtons.YesNo, _
MessageBoxIcon.Warning) = Windows.Forms.DialogResult.No Then
e.Cancel = True
End If
End If
End Sub