Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use savefiledialog in vb.net

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?

like image 592
user2122062 Avatar asked Mar 02 '13 01:03

user2122062


People also ask

What is the use of SaveFileDialog control in VB net?

The SaveFileDialog control prompts the user to select a location for saving a file and allows the user to specify the name of the file to save data. The SaveFileDialog control class inherits from the abstract class FileDialog.

What is the use of SaveFileDialog?

The SaveFileDialog component allows users to browse the file system and select files to be saved. The dialog box returns the path and name of the file the user has selected in the dialog box. However, you must write the code to actually write the files to disk.

How do I save a file in VB NET?

To save your work, click File > Save All. The files are then saved in the Document folder on your computer, inside of a folder called Visual Studio 2019 (or whatever version you have).


1 Answers

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
like image 83
Ken White Avatar answered Sep 23 '22 16:09

Ken White