FileWriteObj.Close()
End Function
在WebForm1.aspx.vb中有如下代码:
Imports System.Data
Imports test_1.MyNetPage
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim WriteString as String = "HELLO"
Dim Net = New NetPage
Net.WriteLineStr = WriteString
Net.FileNamePath = "D:\test.txt"
Net.WriteToFile()
End Sub
出现的状况是:测试下来要输入文本的字符窜(WriteString)和文本名(D:\test.txt)都传送到了WriteToFile()这个函数中,但最后一句FileWriteObj.WriteLine(WriteStr)却没有执行,文本中没有"HELLO"被输入。
我们再来看下不用函数,直接在WebForm1.aspx.vb中写输入文本的代码:
方法二:
Imports System.IO
Imports System.Data
Imports System.Data.SqlClient
Imports test_1.MyNetPage
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim WriteString As String = "HELLO"
Dim strfileobj As StreamWriter
strfileobj = File.AppendText("D:\test.txt"
strfileobj.WriteLine(WriteString)
strfileobj.Close()
End Sub
测试结果成功将HELLO写入了test.txt文本。