La propiedad Filename se asigna cuando el diálogo devuelve una respuesta positiva de diálogo, es decir, cuando cierras el diálogo pulsando el botón
OK, ni antes, ni despues.
Using sfd As New SaveFileDialog
With sfd
.AddExtension = True
.DefaultExt = "jpg"
.FileName = "Image"
.Filter = "Jpeg Image|*.jpg;*.jpeg"
.InitialDirectory = My.Application.Info.DirectoryPath
.OverwritePrompt = True
.Title = "Specify the location where to save the image..."
.ValidateNames = True
End With
If sfd.ShowDialog() = DialogResult.OK Then
Me.ptbFotoPersonal.Image.Save(sfd.FileName, Imaging.ImageFormat.Jpeg)
End If
End Using
También puedes suscribirte al evento FileOk, éste se dispara antes de que la ventana del diálogo se haya cerrado:
Private WithEvents sfd As New SaveFileDialog With
{
.AddExtension = True,
.DefaultExt = "jpg",
.FileName = "Image",
.Filter = "Jpeg Image|*.jpg;*.jpeg",
.InitialDirectory = My.Application.Info.DirectoryPath,
.OverwritePrompt = True,
.Title = "Specify the location where to save the image...",
.ValidateNames = True
}
Private Sub Form1_Load() Handles MyBase.Load
Me.sfd.ShowDialog()
End Sub
Private Sub Sfd_FileOk(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) _
Handles sfd.FileOk
Me.PictureBox1.Image.Save(DirectCast(sender, SaveFileDialog).FileName, Imaging.ImageFormat.Jpeg)
End Sub
Saludos!