Environment.CurrentDirectory changes after publishing the application

Hakan
Hakan used Ask the Experts™
on
I'm using my application in Release folder output and i create several folders in Release folder where my running exe belongs.

and i have lots of Path directions like below;

 Dim dbDir As String = Path.Combine(Environment.CurrentDirectory, My.Settings.str__data_dir, My.Settings.str__data_db)

Open in new window


all my Environment.CurrentDirectory returns different location after i published it and open there.

2019-05-08-01_06_40-Microsoft-.NET-F.png
Is there a way to define these directories? Any help would be grateful.

Thanks.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
AppDomain.CurrentDomain.BaseDirectory; 
Environment.CurrentDirectory; 
Directory.GetCurrentDirectory(); 
Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
System.IO.Path.GetDirectoryName(exePath);
DirectoryInfo binDir = System.IO.Directory.GetParent(exeDir);

Open in new window


Environment.CurrentDirectory, Directory.GetCurrentDirectory();both give you the current working directory. AppDomain.CurrentDomain.BaseDirectory, Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); and others get the directory which contains the executing assembly’s file. Which is where your stuff placed in release should be found.

Like
Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "pathto\mystuff.file");

Open in new window

Author

Commented:
Thank you hilltop in that case i have to define all .CurrentDirectory paths to exact path in that case.
Nothing would prevent you from using the Environment.CurrentDirectory; value in your setup. Even the free NSIS setup compiler would support it. You can always copy whats needed on setup or other..

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial