|
查看: 1644|回复: 5
|
vb.net save data in richtextbox into txt file
[复制链接]
|
|
|
在save button那里,当我要save时,如果manually key in file name, save as new没问题,但要save as replace existing file, 出现问题,有任何意见?
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
SaveFileDialog1.InitialDirectory = "C:\"
SaveFileDialog1.FileName = ""
SaveFileDialog1.Filter = "All Files (*.*) | *.*"
RichTextBoxFR1.SaveFile(SaveFileDialog1.FileName)
SaveFileDialog1.ShowDialog()
End Sub |
|
|
|
|
|
|
|
|
|
|
发表于 11-11-2009 06:28 PM
|
显示全部楼层
你的源码次序有点奇怪……
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
SaveFileDialog1.InitialDirectory = "C:\"
SaveFileDialog1.FileName = ""
SaveFileDialog1.Filter = "All Files (*.*) | *.*"
RichTextBoxFR1.SaveFile(SaveFileDialog1.FileName)
SaveFileDialog1.ShowDialog()
End Sub
不是应该让它出现 Dialog 了才获取档案字串才存取吗? |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 11-11-2009 10:36 PM
|
显示全部楼层
原帖由 吸血骑士 于 11-11-2009 06:28 PM 发表 
你的源码次序有点奇怪……
不是应该让它出现 Dialog 了才获取档案字串才存取吗?
opss...paste 错位子
我放在上面的,但是有error
有没有save richtextbox 的example?要save to replace existing file的 |
|
|
|
|
|
|
|
|
|
|
发表于 12-11-2009 12:00 AM
|
显示全部楼层
把你的 error message 放上来吧……
基本上你的 code 要 overwrite existing file 应该是没有问题的。 |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 12-11-2009 09:02 AM
|
显示全部楼层
原帖由 吸血骑士 于 12-11-2009 12:00 AM 发表 
把你的 error message 放上来吧……
基本上你的 code 要 overwrite existing file 应该是没有问题的。
Error highlight 着 RichTextBoxFR1.SaveFile(SaveFileDialog1.FileName)
Message 是:
IOException was unhandled
The process cannot accessthe file c:\abc.txt because it is being used by another process. |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 12-11-2009 09:34 AM
|
显示全部楼层
找到错误了,FileOpen后没有FileClose。
谢谢骑士~ |
|
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|