码迷,mamicode.com
首页 > Web开发 > 详细

net8:文本文件的创建及其读写

时间:2017-07-10 01:17:07      阅读:249      评论:0      收藏:0      [点我收藏+]

标签:文本   txt   coding   alert   stream   搬家   pos   .config   htm   

原文发布时间为:2008-08-06 —— 来源于本人的百度文章 [由搬家工具导入]

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;


using System.IO;
using System.Text;

public partial class Default3 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {//create and write
        string info = TextBox1.Text;
        string name = TextBox3.Text;

        FileStream fs = new FileStream(Server.MapPath("~/txt/" + name + ".txt"), FileMode.Create, FileAccess.Write);
        StreamWriter sw = new StreamWriter(fs, Encoding.Default);
        sw.WriteLine(info);
        sw.Close();
        fs.Close();
        Response.Write("<script>alert('Create " + name + ".txt')</script>");

    }
    protected void Button2_Click(object sender, EventArgs e)
    {//read
        string name = TextBox4.Text;
        TextBox2.Text = File.ReadAllText(Server.MapPath("~/txt/" + name + ".txt"), Encoding.Default);
    }
}

net8:文本文件的创建及其读写

标签:文本   txt   coding   alert   stream   搬家   pos   .config   htm   

原文地址:http://www.cnblogs.com/handboy/p/7143824.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!