Results 1 to 9 of 9

Thread: Change starting application folder

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2003
    Posts
    219

    Question Change starting application folder

    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?

    Many thanks in advance!

    ljCharlie

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Feb 2003
    Posts
    219
    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.

    ljCharlie
    Attached Images Attached Images  

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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'.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Feb 2003
    Posts
    219

    Question

    Thanks for the response.

    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.

    ljCharlie

  6. #6
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780
    The idea on how to solve this has already been said, you need to use the path of your .exe file, and then change it accordingly:

    System.Reflection.Assembly.GetExecutingAssembly.Location(),

    ^^ that line returns the path of your.exe file. You can just add onto the end your data directory. Use the

    IO.Path.Combine

    to add them together to make

    PATH = IO.Path.Combine(System.Reflection.Assembly.GetExecutingAssembly.Location(), "DatabaseFolder")

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Feb 2003
    Posts
    219
    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.

    ljCharlie
    Last edited by Chong; Dec 8th, 2003 at 03:27 PM.

  8. #8
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780
    You are allowed to use the help file


    System.Reflection.Assembly.GetExecutingAssembly.Location
    Note The Location property returns the full path including the file name; the Path property returned only the path.

    so just use:

    System.Reflection.Assembly.GetExecutingAssembly.Path

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Feb 2003
    Posts
    219

    Thumbs up

    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!

    ljCharlie

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width