asp.net StreamReader Create a file

Source: Internet
Author: User
asp.net|stream| Create

Namespaces used: System.IO
The files we want to create require asp.net users to have certain privileges!

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 the 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)
{
Place user code here to initialize page
Write_file (file_name);
}

//A method of creating a file and entering content in a 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);
&NBSP;&NBSP;&NBSP;SR. WriteLine ("This is my first program.");
&NBSP;&NBSP;&NBSP;SR. WriteLine ("by zixian2005");
&NBSP;&NBSP;&NBSP;SR. Close ();
  }


Code generated #region the Web forms Designer
Override protected void OnInit (EventArgs e)
{
//
CodeGen: This call is required for the ASP.net Web forms Designer.
//
InitializeComponent ();
Base. OnInit (e);
}

<summary>
Designer supports required methods-do not use the Code editor to modify
The contents of this method.
</summary>
private void InitializeComponent ()
{
This. Load + = new System.EventHandler (this. Page_Load);
}
#endregion
}
}




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.