Friday 2 December 2011

How to Create File in C#.net?

File.Create Method (String)
Creates or overwrites a file in the specified path.

Code:
Add Namespace:  System.IO

using System.IO;

protected void btnCreate_Click(object sender, EventArgs e)
    {
        string ls_FilePath = "G:\\";
        string ls_FileName = txtFilename.Text + ".txt";

        try
        {
            File.Create(ls_FilePath + "\\" + ls_FileName);
            lblmsg.Text = "File Created";
        }
        catch(Exception ex)
        {
            lblmsg.Text = ex.Message;
        }
       
    }

No comments:

Post a Comment