Tuesday, July 19, 2011

Creating a dynamically Text File & write in it.........

1.   Add These Two NameSpace in NameSpace Area:

using System.Text;
using System.IO;

2.   And write This code...........

  protected void Button1_Click(object sender, System.EventArgs e)
    {
        string appPath = Request.PhysicalApplicationPath;
        string filePath = appPath + "Text.txt";
        StreamWriter w;
        w = File.CreateText(filePath);
        w.WriteLine("This is a test line.");
        w.WriteLine("This is another line.");
        w.Flush();
        w.Close();
        Label1.Text = "File created and write successfully!";
        Label1.Text += filePath;
    }

No comments:

Post a Comment