asp.net 4.5 练习~test14-6 streamwrite写文件
发布日期:2021-05-06 21:16:24 浏览次数:14 分类:技术文章

本文共 1177 字,大约阅读时间需要 3 分钟。

webform1.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="test14_6.WebForm1" %>

添加新词条

webform1.aspx.cs

using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;namespace test14_6{    public partial class WebForm1 : System.Web.UI.Page    {        protected void Page_Load(object sender, EventArgs e)        {        }        protected void Button1_Click(object sender, EventArgs e)        {            string path = Server.MapPath("test.txt");            string title = TextBox1.Text;            string word = TextBox2.Text;            System.IO.FileInfo file = new System.IO.FileInfo(path);            if (file.Exists == false)            {                System.IO.StreamWriter write1 = file.CreateText();                write1.WriteLine(title);                write1.WriteLine(word);                write1.Flush();                write1.Close();                lblTips.Text = "创建文件并写入数据成功!";            }        }    }}

 

上一篇:asp.net 4.5 练习~test14-7
下一篇:asp.net 4.5 练习~test14-5 写文件

发表评论

最新留言

哈哈,博客排版真的漂亮呢~
[***.90.31.176]2025年03月16日 10时03分37秒