How do I use savefiledialog in vb.net

user2122062 picture user2122062 · Mar 2, 2013 · Viewed 43.6k times · Source

I have a program called TextEditPro and I just started it, I'm running into a problem.

When I had the code for clicking Save As... I don't know how to use the savefiledialog so when you click Save As it will pop up!

Any help?

Answer

Ken White picture Ken White · Mar 2, 2013

Learn to use MSDN - the documentation for SaveFileDialog has an example

Private Sub button1_Click(sender As Object, e As System.EventArgs)
    Dim myStream As Stream
    Dim saveFileDialog1 As New SaveFileDialog()

    saveFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
    saveFileDialog1.FilterIndex = 2
    saveFileDialog1.RestoreDirectory = True 

    If saveFileDialog1.ShowDialog() = DialogResult.OK Then
        myStream = saveFileDialog1.OpenFile()
        If (myStream IsNot Nothing) Then 
            ' Code to write the stream goes here.
            myStream.Close()
        End If 
    End If 
End Sub