Results 1 to 7 of 7

Thread: Accessing files in installation folder

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2001
    Posts
    7

    Accessing files in installation folder

    I've created and deployed an app which includes access to various files that get installed into the Program Files/MyApp folder via the Installer.

    These include an MDB file and some WAV files.

    To create the db connection string, I have used:-

    pathstr = "Provider= Microsoft.Jet.OLEDB.4.0;Data Source="
    pathstr += IO.Path.GetDirectoryName(Application.ExecutablePath)
    pathstr += "\books.mdb"


    I've also tried each of the following ways of trying to point to the mdb and wav files in the C:\ProgramFiles\MyApp folder:


    Application.StartupPath
    IO.Path.GetDirectoryName(Application.ExecutablePath)
    IO.Path.Combine(Application.StartupPath, <MDB FileName>)
    [Assembly].GetExecutingAssembly.Location


    In every case, it works fine if I fire up the application from within the Program Files folder itself. But of course in the real world I want users to run the app from the StartMenu and so have put a shortcut in there for them to use in the usual way.

    And that's where the problem is.

    When the app is fired up from there, the application itself will run OK, BUT all the above variations of paths point to :-

    C:\Documents and Settings\<User Name>\StartMenu\Programs\MyApp

    and so of course the app doesn't find the mdb or wav files because they're not in that folder.

    I'm obviously missing something really simple here, but I just can't seem to track down the right way of pointing the app to those files in all situations.

    So, the question is:- what code should I use to ensure that the app will find the mdb and wav files, no matter which folder it is fired up from - ie. the Start Menu or from within the Program Files folder?


    Any help on this one much appreciated.

  2. #2
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    I use 'Application.StartupPath' and it works correct. It returns the full path and you dont need to use IO.Path.GetDirectoryName......

  3. #3
    Frenzied Member MrGTI's Avatar
    Join Date
    Oct 2000
    Location
    Ontario, Canada
    Posts
    1,277

    Thumbs up

    Like he said, do it like this:
    VB Code:
    1. Dim sStartUpPath As String = Application.StartupPath
    ~Peter


  4. #4

    Thread Starter
    New Member
    Join Date
    Dec 2001
    Posts
    7
    Sorry, guys, but that's just not working.

    Are you saying that if you include similar code to this in the app:-

    Messagebox.Show("The Application.StartUpPath is :- " & Application.StartupPath )

    And then you : -
    1. Create your startup project and deploy the app,
    2. include a shortcut in the Win 2000 Start Menu which points to that App
    3. you fire up the App from the Start Menu
    4. that it will return a result along the lines of

    "The Application.StartUpPath is :- C:\Program Files\XYZSoft\MyTestApp" ?

    Not for me, it doesn't. It returns :

    "The Application.StartUpPath is : - C:\Documents and Settings\Ged Mead\StartMenu\Programs\MyTestApp"

    which is logical and I don't have a problem with why it does that.

    ("MYTestApp" is the name of a folder I added to the Start Menu as part of the deploy routine as well as the name of the folder to which the app is installed in C:\Program Files)

    BUT we're not trying to find the path to the executable file of the app. We're trying to find the path to the folder in which that file has been installed (because the ancillary MDB, WAV, etc files will be in the same place).

    Of course there's some clunky fixes I could consider:
    I could hard code a path for the mdb file on the assumption that the user accepts the default location of C:\Program Files\XYZSoft\TestApp for the installation - but
    we all know the dangers of that road, don't we?

    Or I could force a silent install of the mdb and wav files into a folder of my choosing at install time (without telling the user), but again I don't think that that's the best way to do this.

    So, I'd still be grateful for any other suggestions out there (or, of course, confirmation that it can't be done from any straightforward method offered by dotNet).

    Thanks in advance.

  5. #5
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    I tested that and still it returns the path the program is installed to. So i think there is some problem with your Setup Project. If you are using setup project wizard of .NET be sure to include 'Create New Shortcut' in your "User's Program Menu" not the 'Primary Output' of the project.

  6. #6

    Thread Starter
    New Member
    Join Date
    Dec 2001
    Posts
    7
    Thanks, I'll review my Setup Project and see if I can pin down the prob. This is my first dotNet deployment and it's turning out to be the nightmare I feared (mostly because all the ref books say "It's a breeze to deploy your apps with dotNet".... Kiss of Death, that, in my experience....... )

  7. #7

    Thread Starter
    New Member
    Join Date
    Dec 2001
    Posts
    7

    Deployment Problem (Resolved)

    Thanks, Lunatic3,

    You were spot on - it was the shortcut pointer I'd set up in the Setup Project's File System Editor at the bottom of the problem.

    A bit more attention and time spent on the Help File Walkthrough and I'd have saved myself 36 hours of frustration!

    Oh well, no pain, no gain.

    On to the next problem!


    Cheers

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