SaveFileDialog Conrol in VB.NET 2010

This article shows savefiledialog control in VB.NET 2010.
  • 14078

In this article we will learn about the savefiledialog control in window application in VB.NET.

SaveFileDialog Control

This control are used to save a selected  file. These are the some common properties of SaveFileDialog control:

File name

Property used to get or set file name selected in the file dialog box.

Filter

Property to used to get or set the current file name filter string which sets the choices that appear in 'Save as file type' or 'Files of type' box.

ShowDialog method

To display the dialog box to the user, call the ShowDialog() method.

For example:

click the SaveFileDialog control and openfiledialog control from toolbox it will take place below the form and take two control rich textbox control and two button control to the form.

 s1.gif

Now, double click on the button named openfile in the form and write the following code.

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        OpenFileDialog1.Filter = "All Files|*.*|Text Files|*.txt;*.c;*.cpp;*.cs;*.java"

        OpenFileDialog1.ShowDialog()

        RichTextBox1.LoadFile(OpenFileDialog1.FileName, RichTextBoxStreamType.PlainText)

    End Sub


 

Now, double click on the button named save file in the form and write the following code.


 

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        SaveFileDialog1.Filter = "All Files|*.*"

        SaveFileDialog1.ShowDialog()

        RichTextBox1.SaveFile(SaveFileDialog1.FileName, RichTextBoxStreamType.PlainText)

    End Sub

 

Now press Ctrl+F5 to run the application.
 

The below window will appear and we choose an file to click on the button named open a file and select a file and click on the open button this file text will be display on the rich text box  and than and then click on the button named save a file to save the file proper position.Such as

 

s2.gif
 

Now click on save file button to save the file at the proper place with the file name and also we can write some text in the rich text box to save in a file.

s3.gif
 

Select the path to save the text ROHATASH KUMAR in a file and Give the file name then click on save button.

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.