vb.net 保存文件后不能打开,必须关闭后才能打开文件
打开程序保存的文档提示文档已被其他应用程序锁定,是否已只读方式打开关闭程序后,可以正常打开PrivateSubToolStripMenuItem1_Click(ByVal...
打开程序保存的文档提示文档已被其他应用程序锁定,是否已只读方式打开
关闭程序后,可以正常打开
Private Sub ToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem1.Click
Dim fName As String
SaveFileDialog1.Filter = "文本文件(*.txt)|*.txt" '设定文件类型
DialogResult = SaveFileDialog1.ShowDialog() '显示存档对话方框
If DialogResult = Windows.Forms.DialogResult.Cancel Or _
DialogResult = Windows.Forms.DialogResult.No Then Exit Sub
fName = SaveFileDialog1.FileName '取得文件名
Dim SaveFile As New FileInfo(fName) '建立FileInfo对象
Dim FS As FileStream = SaveFile.Create() '建立FileStream对象
Dim ChArray() As Char = TextSend.Text.ToCharArray '转字符串转为字符数组
Dim i As Integer
For i = 0 To ChArray.GetUpperBound(0)
FS.WriteByte(Asc(ChArray(i))) '写入文件
Next i
End Sub 展开
关闭程序后,可以正常打开
Private Sub ToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem1.Click
Dim fName As String
SaveFileDialog1.Filter = "文本文件(*.txt)|*.txt" '设定文件类型
DialogResult = SaveFileDialog1.ShowDialog() '显示存档对话方框
If DialogResult = Windows.Forms.DialogResult.Cancel Or _
DialogResult = Windows.Forms.DialogResult.No Then Exit Sub
fName = SaveFileDialog1.FileName '取得文件名
Dim SaveFile As New FileInfo(fName) '建立FileInfo对象
Dim FS As FileStream = SaveFile.Create() '建立FileStream对象
Dim ChArray() As Char = TextSend.Text.ToCharArray '转字符串转为字符数组
Dim i As Integer
For i = 0 To ChArray.GetUpperBound(0)
FS.WriteByte(Asc(ChArray(i))) '写入文件
Next i
End Sub 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询