-->

How do I use savefiledialog in vb.net

2019-01-28 10:47发布

问题:

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?

回答1:

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