Namespace used: System.IO
The file we want to create requires the asp.net user to have certain permissions!
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Text;
using System.IO;
namespace new_app
{
/// <summary>
/// Summary description of myxml.
/// </summary>
public class myxml : System.Web.UI.Page
{
private const string FILE_NAME = "d:\MyFile.txt";
private void Page_Load(object sender, System.EventArgs e)
{
//Put user code here to initialize the page
write_file(FILE_NAME);
}
//A method to create a file and enter content in the file
public void write_file(string FILE_NAME)
{
if (File.Exists(FILE_NAME))
{
Console.WriteLine("{0} already exists.", FILE_NAME);
return;
}
StreamWriter sr = File.CreateText(FILE_NAME);
sr.WriteLine ("This is my first program.");
sr.WriteLine ("by zixian2005");
sr.Close();
}
#region Web Forms Designer Generated Code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Forms designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Designer supports required methods - do not use code editor to modify
/// The content of this method.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}