Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. referencing from C: or D: drive

referencing from C: or D: drive

Scheduled Pinned Locked Moved C#
helpquestion
10 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    ploxy
    wrote on last edited by
    #1

    i wrote a little application that install a particular file in drive C. on installing the application on D drive,i had problem calling the file.how can i code for the file to be referenced irrespective of its installation path

    ma coding life

    K N D L 4 Replies Last reply
    0
    • P ploxy

      i wrote a little application that install a particular file in drive C. on installing the application on D drive,i had problem calling the file.how can i code for the file to be referenced irrespective of its installation path

      ma coding life

      K Offline
      K Offline
      kubben
      wrote on last edited by
      #2

      The only idea I can think of involves creating a share folder where you write the file to. Then you could access the file via the share name. So it would be something like: \\computername\sharefoldername\file Of course the down side to this is you need to know the computer name, but that isn't real hard to figure out. Hope that helps. Ben

      N S 2 Replies Last reply
      0
      • P ploxy

        i wrote a little application that install a particular file in drive C. on installing the application on D drive,i had problem calling the file.how can i code for the file to be referenced irrespective of its installation path

        ma coding life

        N Offline
        N Offline
        Not Active
        wrote on last edited by
        #3

        If you install the file in the same folder, or below, as the exe then you can reference it from there. InstallDir: d:\MyApp File path: myfile.txt InstallDir: d:\MyApp\Files File path: /files/myfile.txt


        only two letters away from being an asset

        1 Reply Last reply
        0
        • K kubben

          The only idea I can think of involves creating a share folder where you write the file to. Then you could access the file via the share name. So it would be something like: \\computername\sharefoldername\file Of course the down side to this is you need to know the computer name, but that isn't real hard to figure out. Hope that helps. Ben

          N Offline
          N Offline
          Not Active
          wrote on last edited by
          #4

          :omg::wtf:


          only two letters away from being an asset

          K 1 Reply Last reply
          0
          • N Not Active

            :omg::wtf:


            only two letters away from being an asset

            K Offline
            K Offline
            kubben
            wrote on last edited by
            #5

            I like your answer, but the way I understood the question was that you wouldn't know for sure which drive the file is on. (Of course, that is a little weird/ bad design) So if you don't know the drive letter you could acces it through a share. I suppose sometimes I think too much of answering the question instead of pushing for a better design. My fault. Ben

            1 Reply Last reply
            0
            • P ploxy

              i wrote a little application that install a particular file in drive C. on installing the application on D drive,i had problem calling the file.how can i code for the file to be referenced irrespective of its installation path

              ma coding life

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              How about looking at Application.StartupPath, or Path.GetDirectoryName(Assembly.GetExecutingAssembly.Location).

              A guide to posting questions on CodeProject[^]
              Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                   2006, 2007

              1 Reply Last reply
              0
              • K kubben

                The only idea I can think of involves creating a share folder where you write the file to. Then you could access the file via the share name. So it would be something like: \\computername\sharefoldername\file Of course the down side to this is you need to know the computer name, but that isn't real hard to figure out. Hope that helps. Ben

                S Offline
                S Offline
                snorkie
                wrote on last edited by
                #7

                If the file is on the same drive that the application is on, could you use Environment.CurrentDirectory to figure out which drive you are on. the use relative paths from there to get to your file. Hogan

                D 1 Reply Last reply
                0
                • S snorkie

                  If the file is on the same drive that the application is on, could you use Environment.CurrentDirectory to figure out which drive you are on. the use relative paths from there to get to your file. Hogan

                  D Offline
                  D Offline
                  Dave Kreskowiak
                  wrote on last edited by
                  #8

                  That's a really bad idea. CurrentDirectory is NOT guaranteed to stay that way. Try opening any of the File/Folder dialogs and watch what happens to the current directory during the life of the dialog AND after the dialog. The current directory changes while the user navigates to pick files/folders. The current directory will not return to the original directory when the dialog was shown until after the dialog is dismissed AND the dialog object is told to reset the current directory to what it was when it was shown. Meanwhile, during the users navigation of the file system, the current directory always changes to match where the user is navigating. If you have a multithreaded app that mistakenly depends on current directory, you've got a huge problem!

                  A guide to posting questions on CodeProject[^]
                  Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                       2006, 2007

                  S 1 Reply Last reply
                  0
                  • D Dave Kreskowiak

                    That's a really bad idea. CurrentDirectory is NOT guaranteed to stay that way. Try opening any of the File/Folder dialogs and watch what happens to the current directory during the life of the dialog AND after the dialog. The current directory changes while the user navigates to pick files/folders. The current directory will not return to the original directory when the dialog was shown until after the dialog is dismissed AND the dialog object is told to reset the current directory to what it was when it was shown. Meanwhile, during the users navigation of the file system, the current directory always changes to match where the user is navigating. If you have a multithreaded app that mistakenly depends on current directory, you've got a huge problem!

                    A guide to posting questions on CodeProject[^]
                    Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                         2006, 2007

                    S Offline
                    S Offline
                    snorkie
                    wrote on last edited by
                    #9

                    Thanks for the info. I didn't know that! Hogan

                    1 Reply Last reply
                    0
                    • P ploxy

                      i wrote a little application that install a particular file in drive C. on installing the application on D drive,i had problem calling the file.how can i code for the file to be referenced irrespective of its installation path

                      ma coding life

                      L Offline
                      L Offline
                      Luc Pattyn
                      wrote on last edited by
                      #10

                      Hi, I am a bit surprised by the answers so far. For starters you cant hard code C: or D: or whatever. C: does not even have to exist; I have seen systems that boot and run from D: Second, you cant use CurrentDirectory, as Dave pointed out. You can not even use it if you store its startup value, since one may start an app with its CD preset to whatever value one chooses (try creating a desktop link, and watch its properties). third, wherever the app (the exe file) is located, you are not guaranteed that you can write to that folder. Unless your normal use is only reading that file, you should choose another place. The easy way out is by using the special folders, as can be found in the Environment.SpecialFolder enumeration; you will find some that are user-independent, others are user-specific. So I suggest reading up on that class. :)

                      Luc Pattyn [My Articles] [Forum Guidelines]

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups