In VB.NET project, is there a way to change the starting folder from the "Bin" to the application folder? Here's the problem I'm having. In the VB.NET project, when I run my application, it always start in the Bin folder. But when I compiled my program as an application an install it to another machine, the program starts in the application folder...and not Bin folder anymore. I want to be consisting because I have a .mdb file database in the Bin folder. I used this Private Shared mdbPath As String = Application.StartUpPath & "\myFile.mdb" to get my path. And because in the project, the program starts in the Bin folder so this is fine...however, when I compiled the program and install to new computer, the startup path is no longer started in the Bin folder anymore. So is there a way to get this to be consistant?
When starting from the IDE your program starts in the bin folder because the bin folder IS the application folder. The bin folder is where the IDE compiles your exe to. Using Application.StartupPath should work fine but if for some reason it doesn't then do a search in the .NET section of the forums for App.Path. App.Path was the VB6 way to get the application folder and there are many ways to do this in .NET all of which have been posted before so they will come up in a search.
Many thanks for your response. It's not that Application.StartUpPath isn't working, the problem lies when I deploy the application. In the attachment, I have a picture of the File System that I use to build a deployment of my application.
Now, when I build it this way and install the application to a new machine, the program is no longer start in the Bin folder and this is why I have the error not finding my .mdb file.
In the picture, my .mdb file is in the Bin folder.
You shouldn't include the bin folder itself in the deployment, just include the files you want (like the db) and put them in the Application Folder. See when you run it in the IDE your exe and db are in the same folder, this is known as the application folder, when running from the IDE the application folder IS the bin. But when you deploy its just wherever the user wants so just put the files in the application folder in your deployment project. Your exe and what not are already in there listed as 'Primary Output' the db just needs to be in that folder instead of your subfolder named 'bin'.
The issue is, I want to have my external files and db file to be in a separate folder inside the application folder. I think this is a better way to keep track of all my external files. However, if I got it working in my project then it doesn't work when I deploy the application to another computer. And if got it working when deploying the application to another computer then it doesn't work when running in my project. I like to know if there is a way to fix this so I can have a separate folder inside the application folder and works in both palces.
Many thanks for the information; however, I still have problems with the code you gave me.
The code PATH = IO.Path.Combine(System.Reflection.Assembly.GetExecutingAssembly.Location(), "DatabaseFolder") return this path C:\VB_Project\Computers\bin\Computers.exe\DatabaseFolder And there is no such folder as Computers.exe. I guess I still don't understand it. This line of code System.Reflection.Assembly.GetExecutingAssembly.Location() returned the file name of the application, in this case Computers.exe, and not the folder name of the application. And so when I used the IO.Path.Combine with System.Reflection.Assembly.GetExecutingAssembly.Location(), I get the C:\VB_Project\Computers\bin\Computers.exe\DatabaseFolder. And this isn't working.
System.Reflection.Assembly.GetExecutingAssembly.Location
Note The Location property returns the full path including the file name; the Path property returned only the path.
Thanks Guys! I guess you can say I'm stupid or slow...but YES, I got it working. All of this time and I have not figured it out but then when I thought what Edneeis said "just include the files you want (like the db) and put them in the Application Folder", I created the DataFolder inside of the bin folder, which is where my .exe file is. Now it works!