Default file name for SaveFileDialog

  • Thread starter Thread starter moondaddy
  • Start date Start date
M

moondaddy

How can I set a default file name when the SaveFileDialog opens? In this
scenario the user will almost always use the default name supplied by my
code.
 
SaveFileDialog1.FileName = "MyName"--- your default name

Put that before the SaveFileDialog1.ShowDialog()
Of course, doing it this way, your user can still change the filename.
james
 
I tried that but it seemed to have no effect. Perhaps my problem is related
to my other post titled "Trouble setting properties in saveFileDialog". Any
ideas why it wouldn't open showing these property settings?

--
(e-mail address removed)
james said:
SaveFileDialog1.FileName = "MyName"--- your default name

Put that before the SaveFileDialog1.ShowDialog()
Of course, doing it this way, your user can still change the filename.
james
 
Here is a bit of code to help you:
Private Sub mnuSaveAs_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnuSaveAs.Click

Dim img2 As Image

With sdlgImage 'sdlgImage is the name I gave the SaveFileDialog1 control

..InitialDirectory = "C:\"

..FileName = "myimage"

..Filter = "Bitmap (*.bmp)|*.bmp|GIF (*.gif)|*.gif|JPEG (*.jpg)|*.jpg|TIF
(*.tif)|*.tif|PNG (*.png) |*.png"

..FilterIndex = 1

End With

If sdlgImage.ShowDialog() = DialogResult.OK Then

Dim strMsg As String

PictureBox1.Image.Save(sdlgImage.FileName, GetImageFormat())

strMsg = "Image successfully saved to " & sdlgImage.FileName



MessageBox.Show("Image successfully saved to " & _

sdlgImage.FileName, Me.Text, _

MessageBoxButtons.OK, MessageBoxIcon.Information)

End If

End Sub

Put this in the Click event of the button or Menu Item you are using to save
your image and you should be ok.

You also want to be able to get the image format of the image you are saving
here is how:

Private Function GetImageFormat() As ImageFormat

Select Case sdlgImage.FilterIndex

Case 1

Return ImageFormat.Bmp

Case 2

Return ImageFormat.Gif

Case 3

Return ImageFormat.Jpeg

Case 4

Return ImageFormat.Tiff

Case Else

Return ImageFormat.Png

End Select

End Function



That should get you going.

james






moondaddy said:
I tried that but it seemed to have no effect. Perhaps my problem is related
to my other post titled "Trouble setting properties in saveFileDialog". Any
ideas why it wouldn't open showing these property settings?
 
Thanks I can use some of that code. I found my problem. It was in the
order of the following lines of code. When i used the following code in the
order listed everything worked. here it is for anyone who's interested.


SaveFileDialog1.FilterIndex = 1
SaveFileDialog1.DefaultExt = sExt
SaveFileDialog1.InitialDirectory = sTargetPath
SaveFileDialog1.FileName = sFileName
SaveFileDialog1.Filter = "JPeg Image|*.jpg|Bitmap Image|*.bmp|Gif
Image|*.gif"
SaveFileDialog1.Title = "Save an Image File"
SaveFileDialog1.ShowDialog()
sTargetPath = SaveFileDialog1.FileName
 
Back
Top