| | |
VB.NET - Using streamreader with relative path.
![]() |
•
•
Join Date: Nov 2004
Posts: 2
Reputation:
Solved Threads: 0
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\<projectname>\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?
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\<projectname>\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?
•
•
•
•
Originally Posted by Tengu
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\<projectname>\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?
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
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
Mark Nemtsas
Time and Billing Software - Time Tracking Software - Roller Shutters - Roller Blinds -
Baby Books
Time and Billing Software - Time Tracking Software - Roller Shutters - Roller Blinds -
Baby Books
•
•
•
•
Originally Posted by Tengu
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\<projectname>\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?
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
sr = New StreamReader(System.AppDomain.CurrentDomain.BaseDirectory & "file.txt")
Try that.
Mark
Mark Nemtsas
Time and Billing Software - Time Tracking Software - Roller Shutters - Roller Blinds -
Baby Books
Time and Billing Software - Time Tracking Software - Roller Shutters - Roller Blinds -
Baby Books
Double Post
Mark Nemtsas
Time and Billing Software - Time Tracking Software - Roller Shutters - Roller Blinds -
Baby Books
Time and Billing Software - Time Tracking Software - Roller Shutters - Roller Blinds -
Baby Books
![]() |
Similar Threads
- Relative Path (VB.NET)
- Relative path (VB.NET)
- how to set relative path in a .config file? (Java)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: Low Quality in VB when printing with printer.paintpicture
- Next Thread: Nested For Next Loops w/ Triangles
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age application basic beginner birth bmp calculator cd cells.find click client code college component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report save search sendbyte sites sort sql sql2008 sqlserver subroutine tags textbox time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows





