Use of savefiledialog box for saving files

Posted by Ddd under Windows Forms category on | Points: 40 | Views : 3134
1)Open a windows application.
2)On the form paste a button, richtextbox. also add a savefiledialog.

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 WindowsFormsApplication3
public partial class Form1 : Form
public Form1()

private void button1_Click(object sender, EventArgs e)
saveFileDialog1.Filter = "all files|*.*|text files|*.txt";
saveFileDialog1.InitialDirectory = "C:\\";

if (saveFileDialog1.ShowDialog() == DialogResult.OK)
richTextBox1.SaveFile(saveFileDialog1.FileName, RichTextBoxStreamType.PlainText);
MessageBox.Show("file saved");
richTextBox1.Text = "";


Comments or Responses

Login to post response