VB.NET - Using streamreader with relative path.

Reply

Join Date: Nov 2004
Posts: 2
Reputation: Tengu is an unknown quantity at this point 
Solved Threads: 0
Tengu Tengu is offline Offline
Newbie Poster

VB.NET - Using streamreader with relative path.

 
0
  #1
Nov 8th, 2004
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?
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 200
Reputation: mnemtsas is an unknown quantity at this point 
Solved Threads: 1
mnemtsas's Avatar
mnemtsas mnemtsas is offline Offline
Junior Poster

Re: VB.NET - Using streamreader with relative path.

 
0
  #2
Nov 8th, 2004
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?
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:

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. 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
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 200
Reputation: mnemtsas is an unknown quantity at this point 
Solved Threads: 1
mnemtsas's Avatar
mnemtsas mnemtsas is offline Offline
Junior Poster

Re: VB.NET - Using streamreader with relative path.

 
0
  #3
Nov 8th, 2004
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?
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:

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. sr = New StreamReader(System.AppDomain.CurrentDomain.BaseDirectory & "file.txt")

Try that.

Mark
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 200
Reputation: mnemtsas is an unknown quantity at this point 
Solved Threads: 1
mnemtsas's Avatar
mnemtsas mnemtsas is offline Offline
Junior Poster

Re: VB.NET - Using streamreader with relative path.

 
0
  #4
Nov 8th, 2004
Double Post
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 2
Reputation: Tengu is an unknown quantity at this point 
Solved Threads: 0
Tengu Tengu is offline Offline
Newbie Poster

Re: VB.NET - Using streamreader with relative path.

 
0
  #5
Nov 8th, 2004
Thanks for the help. Second one did the trick.

sr = New StreamReader(System.AppDomain.CurrentDomain.BaseDirectory & "bin\file.txt")
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC