- This topic explains about the working of SaveFileDialog component in C# programming.
- With this you can save file into your location.
- Tools needed: Button1 (Button1), SaveFileDialog1 (SaveFileDialog1), RichTextBox1 (RichTextBox1).
C#.NET – Working of SaveFileDialog Component in C#
- C# is an Object Oriented Programming language from Microsoft that mainly combines the computing power of C++ with the programming ease of Visual Basic.
- C# is mainly based on C++.
- The most recent version is C#4.0.
- C# language is simple, modern, general-purpose, object-oriented language.
SaveFileDialog Class – Working of SaveFileDialog Component in C#
- Help the user to select a location for saving a file.
- This class cannot be inherited.
Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
- Syntax for SaveFileDialog
|
1 2 3 |
// Declaration public sealed class SaveFileDialog : FileDialog { } |
CommonDialog.ShowDialog Method – Working of SaveFileDialog Component in C#
- Help to run a common dialog box with a default owner.
Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
- Syntax for ShowDialog
|
1 2 3 |
// Declaration public void ShowDialog(void As, void DialogResult) { } |
FileDialog.FileName Property – Working of SaveFileDialog Component in C#
- Help to sets a string containing the file name selected in the file dialog box.
- Syntax
|
1 2 3 |
// Declaration public string FileName { } |
RichTextBox Class – Working of SaveFileDialog Component in C#
- Help to represent a windows rich text box.
- Syntax
|
1 2 3 4 5 6 |
// Declaration [ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)] [ComVisibleAttribute(true)] [DockingAttribute(DockingBehavior.Ask)] public class RichTextBox : TextBoxBase { } |
RichTextBox.SaveFile Method (String, RichTextBoxStreamType)
- Help to saves the contents of the RichTextBox to a specific type of file.
- Parameters
Path – The name and location of the file to save.
File Type – One of the RichTextBoxStreamType values.
Working of SaveFileDialog Component in C# – Complete Code
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { if (SaveFileDialog1.ShowDialog() == DialogResult.OK) { RichTextBox1.SaveFile(SaveFileDialog1.FileName, RichTextBoxStreamType.PlainText); } } } } |
Working of SaveFileDialog Component in C#






