Jump to content
  • Advertisement
Sign in to follow this  
xg0blin

[.net] vb.net and paths

This topic is 5404 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Why is it that when I try to use a streamreader, it always looks in c:\winnt\system\ instead of the current directory. I even tried telling it to read "./Filename.txt". What in the hell. Is there a way to tell it you want it to look in the same damned folder as your executable is running in (the path you should be in anyways). I can't have a fully qualified path name as it will be running on all different computers and this is pissing me off greatly :)

Share this post


Link to post
Share on other sites
Advertisement
Use Environment.CurrentDirectory

Dim yourfilename As String = "hey.you"
Dim r As StreamReader = New StreamReader(Environment.CurrentDirectory + yourfilename)



EDIT:fixed the source

Share this post


Link to post
Share on other sites
the relative path approach works fine for me - are you sure you have filename.txt in the same directory as your executable? (not your project)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Ok, I got it. CurrentDirectory gave me that. I'm doing web applications so I am actually in a virtual directory, so if you check the path you get that. What I have to call for the current directory is this:

System.AppDomain.CurrentDomain.BaseDirectory.ToString()

That does the job.

Share this post


Link to post
Share on other sites
What I meant to say, posting as myself (damned no warning) is this:

Ok, I got it. CurrentDirectory gave me the same thing as the . did. I'm doing web applications so I am actually in a virtual directory, so if you check the path you get the winnt path instead of the real path (I take it that it has something to do with where the server is serving the pages or something?). What I have to call for the current directory is this:

System.AppDomain.CurrentDomain.BaseDirectory.ToString()

That does the job. Thanks for the help.

Share this post


Link to post
Share on other sites
Just a side note, why not add the full path to the files needed to the config file, then call the config setting from inside the application. It is always best to have paths dynamic and not hard coded, it will ease deployment and allow the user to move the files to other directories.

In the case of a web app, you would have to allow the user to be able to write to the virtual directory, I would prefer the user to have only read acces to an open directory and then use ACL's to control the configuration and data directories.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!