0

I'm making a windows form application, and I want to create a check for a folder, which I know how to do, but I don't want it to be

"C:\Users\User\Documents\Visual Studio 2015\Projects\This Project\Required Files\file.txt"

But

"This Project\Required Files\file.txt"

is that possible? I need to do this because I want to app to be portable, and if I put the whole path starting with C and the app is installed somewhere else (For EG. C:\User\Bob\Application\Required Files\file.txt") Thanks.

maky55
  • 21
  • 1
  • 7
  • Put the folder in `Users` or `Program Data` depending on how you use it. If you make it a child of the app install folder you may not have permission to the data file at run time – Ňɏssa Pøngjǣrdenlarp Nov 24 '16 at 23:35
  • http://stackoverflow.com/questions/6041332/best-way-to-get-application-folder-path – Slai Nov 25 '16 at 00:11

2 Answers2

2

You can do something like. For example you a folder the has 2 sub-folders

1.My Program

2.Required Files

The folder My Program contains your program .exe for example

and the folder Required Files has the files.txt

you can do something like this in your code.

Dim path as string = App.Path & "\Required Files\file.txt"

so what will happen is that whereever your program will installed the Required File folder will follow. The App.Path will create the rest of the folder location + the assigned folder that you have and that is "\Required Files\file.txt"

See? Relationship goals hahaha kidding.

I didnt see that you have another folder called Project you just do this.

Dim path as string = App.Path & "Project\Required Files\file.txt"

I hope this one helps.

Shadow Fiend
  • 351
  • 6
  • 18
1

You can even use Application.StartupPath. Or split the complete path and take the records at the position that you want.

Dim Path() as string = application.StartupPath().split("\"c)

Check Path() in a debug and take what you need.

Tyler
  • 416
  • 4
  • 11