|
-
Dec 28th, 2007, 06:21 PM
#1
-
Dec 28th, 2007, 06:35 PM
#2
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.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Dec 28th, 2007, 06:44 PM
#3
Re: SaveFileDialog Problem
 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?
-
Dec 28th, 2007, 06:58 PM
#4
Hyperactive Member
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.
Last edited by Desolator144; Dec 28th, 2007 at 07:01 PM.
I tried to end process on Visual Studio 2005
but PETA stopped me saying it's smart enough
to be a living creature 
-
Dec 28th, 2007, 07:22 PM
#5
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.
Last edited by VBDT; Dec 28th, 2007 at 07:35 PM.
-
Dec 28th, 2007, 08:24 PM
#6
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
Last edited by VBDT; Dec 29th, 2007 at 04:32 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|