How to Save File using C# Windows Application

Hi programmers, welcome to new article of c# windows application. This article i’ll write program to Save File using c# Windows Form. We can achieve the output StreamWriter class , write method ,Random class. In the Form Designer i drag and drop one button,one textbox,one label controls. Set MultiLine property of TextBox False into True. Let’s see the program.

1.Form Design with controls . see below image.

2. Double Click on Save button control. Button click1 event open. Write below codes.

Use this below codes directly into Editor.

using System;
using System.Drawing;
using System.IO;
using System.Windows.Forms;

namespace WindowsFormsApp5
    public partial class Form1 : Form
        public Form1()

        private void button1_Click(object sender, EventArgs e)
            StreamWriter tw = new StreamWriter(@"C:\Users\Adam\Desktop\James\hello.txt");
            label1.Text = "File Save Successfully";
            Random r = new Random();
            label1.ForeColor = Color.FromArgb(r.Next(0, 256), r.Next(0, 256), 0);

Happy coding…Thanks.

Post Author: adama