Saving Text files in C#
Step 1- we need to add Textbox & Button.
Step 2-Here is the code copy & paste to the button1 click event.
using System;
using System.Windows.Forms;
using System.IO;
namespace Save_text_file
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "Text file (*.txt)|*.txt|C# file (*.cs)|*.cs";
sfd.ShowDialog();
File.WriteAllText(sfd.FileName, textBox1.Text);
MessageBox.Show("Details saved");
}
}
Step 1- we need to add Textbox & Button.
Step 2-Here is the code copy & paste to the button1 click event.
using System;
using System.Windows.Forms;
using System.IO;
namespace Save_text_file
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "Text file (*.txt)|*.txt|C# file (*.cs)|*.cs";
sfd.ShowDialog();
File.WriteAllText(sfd.FileName, textBox1.Text);
MessageBox.Show("Details saved");
}
}