如何将文本框数据保存到RTF或DOC文件中 [英] how to save textbox data into RTF or DOC file

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

问题描述

你好朋友,

今天我又回来了一个新问题.
我在vb.net屏幕上有一个MultiLine文本框
还有一个名为Save
的按钮

如何将文本框数据保存到RTF或DOC文件中.在保存按钮上单击事件.


注意:
我不想使用任何第三方控件.
以及我不想使用任何库.
而且我不想使用microsoft.interop.


请帮助我,保存按钮点击事件.

我也想重新加载该文件.在加载文件时单击事件...

Hello Friends,

Today i am back with a new question.
I have a multiLine TextBox On my vb.net screen
And there is a button with name Save


how can i save the textBox data in RTF or DOC file.On save button click event.


Note:
I dont want to use any third party control.
as well as i dont want to use any library.
and i dont want to use microsoft.interop.


please help me how can i do this.on save button click event.

and i want to reload that file also.on load file click event...

推荐答案

// check for file present 

if (File.Exists("E:\\test.rtf"))
    {
       File.Delete("E:\\test.rtf");
    }

// using stream writer class
  StreamWriter sw = new StreamWriter("E:\\test.rtf");

// textbox1 is richtext box

  sw.WriteLine(textBox1.Text);

//close your stream
  sw.Close();


如果您的RichTextBox有很多可用的信息..

请参阅以下页面

http://msdn.microsoft.com/en-us/library/aa970917.aspx

http://stackoverflow.com/questions/688660/ http://www.c-sharpcorner.com /UploadFile/6897bc/richtextbox-sample-saving-the-content-to-text-file/ http://www.c-sharpcorner.com/Forums/Thread/47405/

祝您阅读愉快!
If you richtextbox there is plenty of information availalble..

Refer the pages below

http://msdn.microsoft.com/en-us/library/aa970917.aspx

http://stackoverflow.com/questions/688660/saving-loading-richtextbox-content-with-other-data-using-c-sharp

http://www.c-sharpcorner.com/UploadFile/6897bc/richtextbox-sample-saving-the-content-to-text-file/

http://www.c-sharpcorner.com/Forums/Thread/47405/

Happy reading!!


使用此代码可以确保解决您的问题,在文件路径中使用扩展名".doc"的文件名

use this code it will sure solve your problem,in file path give file name with ''.doc'' extension

Public Sub WriteTextdataInDocFile(ByVal FilePath As String,ByVal inputString As String)
        
        Dim fl As System.IO.File
        fl.WriteAllText(FilePath, inputString)

    End Sub


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

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