如何将文本框数据保存在文件中 [英] How to save Textbox data in a file

查看:76
本文介绍了如何将文本框数据保存在文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Windows应用程序上工作,我想在单击我的按钮并且文件扩展名是.html时将文本框日期保存在文件中.



谢谢Adv ..

问候
Sham

i m working on windows application and i want to save textbox date in a file when i button clicked and file extension is .html .



Thanks in Adv..

Regard
Sham

推荐答案

using System;
using System.IO;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        //
        // This is the button labeled "Save" in the program.
        //
        File.WriteAllText("C:\\demo.html", textBox1.Text);
    }
    }
}


或在按钮单击事件中使用此..


or Use this in button click event..

//Use StreamWriter class.
StreamWriter sw = new StreamWriter("E:\\test.html");
 
//Use write method to write the text
sw.Write(textBox1.Text);
 
//always close your stream
sw.Close();


也可以看到它..
http://www.dotnetspider.com/resources/31161-正在创建带有文本框的html文件 [


Also can see it..
http://www.dotnetspider.com/resources/31161-Creating-html-file-with-text-box-data.aspx[^]


这篇关于如何将文本框数据保存在文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆