asp.net StreamReader Instance code to create a file

Source: Internet
Author: User
This article describes the ASP.net StreamReader to create a file instance code, you need friends can refer to the copy code code as follows:


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; A summary description of the
namespace New_app
{
 ///<summary>
 ///myXML.
 ///</summary>
 public class myxml:System.Web.UI.Page
 {
  Private Const STR ing file_name = "d:myfile.txt";
  private void Page_Load (object sender, System.EventArgs e)
  {
  //Place user code here to initialize the page &nbs p;  
   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);
   Sr. WriteLine ("This is my first program.");
   Sr. WriteLine ("by zixian2005");
   Sr. Close ();
 }
  #region The code generated by 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 the desired method-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
 }
}

Related Article

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.