It crashed on sw = New StreamWriter(fileName). The error message was "The process cannot access the file 'C:\test.txt' because it is being used by another process". Why was wrong?
Thanks.
DanYeung
VB.NET:
Dim fileName As String = Application.StartupPath & "\Test.txt"
Dim myStream As Stream
SaveFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
SaveFileDialog1.FilterIndex = 2
SaveFileDialog1.RestoreDirectory = True
If SaveFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
Dim sw As StreamWriter
Try
myStream = SaveFileDialog1.OpenFile()
If (myStream IsNot Nothing) Then
sw = New StreamWriter(fileName)
sw.WriteLine(Me.TextBoxName.Text)
sw.WriteLine(Me.TextBoxID.Text)
sw.Flush()
myStream.Close()
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
sw.Close()
End Try
End If
DanYeung
Last edited by a moderator: