Reputation: 116
I have tested the following two codes .The first one works as I'm giving the full path name but the second one give the error saying the file is not found.The value of the path location is shown same in both the cases.I think i'm not concatenating the stings right.I have also tried to give the filename without the extension.Any help?
1st code
Dim content As String
Dim path As String
path = "C:\Users\****\bin\Debug\tns.txt"
MessageBox.Show(path)
Try
Dim sr As New StreamReader(path)
content = sr.ReadToEnd()
Console.WriteLine(content)
MessageBox.Show(content)
Catch ex As Exception
MessageBox.Show(ex.Message.ToString())
End Try
2nd code
Dim content As String
Dim path As String
path = Directory.GetCurrentDirectory() + "\tns.txt"
MessageBox.Show(path)
Try
Dim sr As New StreamReader(path)
content = sr.ReadToEnd()
Console.WriteLine(content)
MessageBox.Show(content)
Catch ex As Exception
MessageBox.Show(ex.Message.ToString())
End Try
Upvotes: 0
Views: 5986