I am making a VB.NET web application in VS.NET 2003.
I am using streamreader to access a text file for reading. I am able to access it without any problems using the full path (ie. C:\Inetpub\wwwroot\\bin\file.txt). But I want to use a relative path (ie. .\file.txt).
If I use something like:
Dim sr As System.IO.StreamReader sr = New StreamReader(".\file.txt") 'or just "file.txt"
I get the following error:
Could not find file "c:\windows\system32\inetsrv\file.txt". Source Error: Line 62: sr = New StreamReader(".\file.txt")
Why does it automatically default to the directory "c:\windows\system32\inetsrv\"? What should I do to change this?
You're better off asking this in the .NET forum, and I've only dabbled in .NET. But here's one way to do it:
sr = New StreamReader(System.Windows.Forms.Application.ExecutablePath & "\file.txt")
I don't have VB.NET on this PC so I can't test it. I'm pretty sure that's how you would do it though :mrgreen:
Try that.
Mark