# [.net] working directory

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

## Recommended Posts

If I never change my working directory, is it safe to just use relative directories such as "Graphics\img001.png" instead of "C:\...\MyApp\Graphics\img001.png"?

##### Share on other sites
Quote:
 Original post by nagromoIf I never change my working directory, is it safe to just use relative directories such as "Graphics\img001.png" instead of "C:\...\MyApp\Graphics\img001.png"?

Yes, but never a good idea to just assume those directories are going to be there (i.e. someone might cwd before running your app) - best to check the cwd, and check for the existence of the directories / files.

##### Share on other sites
I use relative directories myself, but if I were making a program I planend to distribute, I'd have a "long" prefix of the full path name (that could be changed) and just tack the local directories on to the end of that.

##### Share on other sites
..or you could find the path in which your application is running with AppDomain.CurrentDomain.BaseDirectory

##### Share on other sites
Quote:
 Original post by Anonymous Poster..or you could find the path in which your application is running with AppDomain.CurrentDomain.BaseDirectory
I'd (being another AP) say *should* rather than *could*. Current directory is an ugly thing to rely on, find out where your .exe is executing and build your absolute path from there.

##### Share on other sites
Quote:
 Original post by PeonI use relative directories myself, but if I were making a program I planend to distribute, I'd have a "long" prefix of the full path name (that could be changed) and just tack the local directories on to the end of that.

I don't like using relative paths either.
I am also never sure what uses the current directory. .NET functions obviously do, but do DirectX functions for example?

##### Share on other sites
So would this be a good way to do it:

public Texture(string xFilename) {	Bitmap lImage = new Bitmap(AppDomain.CurrentDomain.BaseDirectory + xFilename);	CreateTextureFromBitmap(lImage);}

Also, if this code was in a .dll (maybe in a different directory from the exe) would it still use the .exe's path?

##### Share on other sites
Mmm, not sure - I think it will use the path of the DLL. However Application.StartupPath() uses the path of the exe that started the process it is being called in. It doesn't include the exe's name in this string.

• 18
• 29
• 11
• 21
• 16