0

How do I make sure SaveAs Dialog return a filename with the extension?

For Example:

'Test' (.txt) return 'test.txt'

But:

'Test 1.0' (.txt) return 'Test 1.0' (Should be 'Test 1.0.txt')

Possible solution: I can manually check if there is a '.txt' at the end, but if there are two extension types (.txt, .doc), how do I know which one the user selected?

Thank you!

Gerhard Powell
  • 5,965
  • 5
  • 48
  • 59

1 Answers1

1

I believe you need to set the .SupportMultiDottedExtensions to True, like so:

Using tDialog As SaveFileDialog = New SaveFileDialog
With tDialog
        .Filter = "Text Files|*.txt"
        .SupportMultiDottedExtensions = True
        .ShowDialog()
        MsgBox(.FileName)
    End With
End Using
Sam Axe
  • 33,313
  • 9
  • 55
  • 89
  • Thank you for your answer. I tried that already and it did not solve the issue. – Gerhard Powell Mar 06 '12 at 23:29
  • Odd. It works for me. Run the code in the example I provided and you will see. – Sam Axe Mar 06 '12 at 23:42
  • Odd that it work for you and not for me. Tested your example in a blank Visual Studio 2010 project, VB and C# and both it not solve the issue. – Gerhard Powell Mar 07 '12 at 17:04
  • Did you set the Filter property correctly? You must have a properly constructed Filter for this to work. – Sam Axe Mar 07 '12 at 17:55
  • Thank you for your support. I have copied your example directly into a new project, and it was not working. I see that you can get the filter back, and use that to detect the filter used. Another option is to make a default name with the extension already in the name. They are good workarounds, but does not solve the issue. – Gerhard Powell Mar 07 '12 at 21:11
  • So using the code above here's the steps I take.. compare to your steps and lets see where things differ: new VB winforms project, drop a button on form, in button click event place code from above. run, click button, in filename textbox type: "file 1.0", press Save button. At this point I see a messagebox with "c:\users\myusername\desktop\File 1.0.txt" – Sam Axe Mar 07 '12 at 21:41
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/8651/discussion-between-gerhard-powell-and-boo) – Gerhard Powell Mar 07 '12 at 22:08