How to create default folder structure with publish of application in vb.net

Hakan
Hakan used Ask the Experts™
on
I'm working on application which requires different type of inputs and i'm storing that required files and folder in my "Release" output folder.

Also i'm using that paths in mycodes like below format;

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

Open in new window


In fact when i'm running in "Release" , Environment.CurrentDirectory is D:\TestCode but after i published the code all my paths is changed to RoamingData folder as you can see on error message when my application didn't found the path.

2019-05-08-01_06_40-Microsoft-.NET-F.png
After that  i asked a question and realize i shouldn't built my path structure to Environment.CurrentDirectory.

So now i wonder when we're installing a commerical software that comes with several folder structure(like below image), what's the approach that programs use this directories.

I'm asking this because i'll be creating different folder structures and i want to access them in all cases.

Any help would be grateful.

2019-05-08-23_08_25-Window.png
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Chinmay PatelChief Technology Ninja
Distinguished Expert 2018

Commented:
Hi Hakan,


Using current working directory is a right approach. In your case things might not have worked as it expects files to be deployed along with the folder.

And Environment.CurrentDirectory will always give you fully qualified path of the current working directory.

If you are not setting it manually or by mistake, and if you start your app from D:\TestCode, it should look for the database under D:\TestCode only.

Regards,
Chinmay.

Author

Commented:
Hi Chimnay,

It's published as ClickOnce application. Is that causing that ?
Chief Technology Ninja
Distinguished Expert 2018
Commented:
I suspected that. ClickOnce works a bit differently and of course is always installed under User's profile.

You should use
Assembly.GetExecutingAssembly

Open in new window

to get the exact folder location from where your app has started executing.

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