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. The Lounge
  3. Coding file paths to a server or network share

Coding file paths to a server or network share

Scheduled Pinned Locked Moved The Lounge
sysadminhelpquestion
37 Posts 28 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.
  • A AspDotNetDev

    Whatever you do, don't hard code it. I have had to deal with too many old servers over several jobs that can't be upgraded because somebody hardcoded a path rather than putting it into a configuration file or creating an options dialog that allows the user to change it. I would also avoid the mapping.

    Driven to the ARMs by x86.

    R Offline
    R Offline
    Rutvik Dave
    wrote on last edited by
    #7

    OK, so it took me 4 min to write one post! damn!

    It's a shame that stupidity can't be converted into a usable energy source.

    1 Reply Last reply
    0
    • S Slacker007

      We do a lot of in-house software and utilities that access network shares and servers. I usually code the path like so:

      \\MYSERVER001\SomeCrazyDirectory

      Some of my colleagues code the path of the mapped drive (on their workstation). Problem is, if you put the app on someone's workstation/computer it won't work unless they have the exact same mapping, which doesn't always work out. Am I looking at this the wrong way?

      ----------------------------- Just along for the ride. -----------------------------

      W Offline
      W Offline
      wizardzz
      wrote on last edited by
      #8

      I agree with the 2 previous posts, and you. Use the path to the server, not mapped drive, but move it to a config file, too. I get scared of hard coded shit like that, but believe me the software here is loaded with it.

      "I have a theory that the truth is never told during the nine-to-five hours. " — Hunter S. Thompson

      1 Reply Last reply
      0
      • S Slacker007

        We do a lot of in-house software and utilities that access network shares and servers. I usually code the path like so:

        \\MYSERVER001\SomeCrazyDirectory

        Some of my colleagues code the path of the mapped drive (on their workstation). Problem is, if you put the app on someone's workstation/computer it won't work unless they have the exact same mapping, which doesn't always work out. Am I looking at this the wrong way?

        ----------------------------- Just along for the ride. -----------------------------

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #9

        You shouldn't hard-code the path names, however you specify them. Put them in a config file / database table or something that can just be changed without re-deploying. If your environment is one in which the mapped drives are system administered (which, evidently, they're not!) then using mapped drives is a good way of locating the data that provides the information about where on the network stuff resides... e.g. have a system wide map of Z: to some folder in that folder have a config file of some description that holds information about the locations of everything (i.e. if your location information is in a database, it may store the information to log into that database and gain access to the location information, if your location info is in an XML file, then it will have information pointing to that XML file on the network (NOT using a Share) This way, you have a single, central location in which you can make any changes and immediately affect all users. All of your applications local config file then specifies Z:\whatever as the location for the config. now, if the Z: mapped drive changes, you need to just change the mapping centrally (worse case you need to change the mapping on every machine) if the location of any other info changes, you just need to go to the Z: drive, and edit the config to either point to the new location, or find the reference to the location in which the location information is stored (blimey, the English language wasn't made for this sort of explanation!) Your co-workers may argue that if everyone had the same mapped drive, then all would be well, and that if stuff moves around the network you just need to change the map - but that too is dangerous as there may be a requirement to move some, but not all, of the stuff from that mapped drive to another location.

        MVVM# - See how I did MVVM my way ___________________________________________ Man, you're a god. - walterhevedeich 26/05/2011 .\\axxx (That's an 'M')

        1 Reply Last reply
        0
        • S Slacker007

          We do a lot of in-house software and utilities that access network shares and servers. I usually code the path like so:

          \\MYSERVER001\SomeCrazyDirectory

          Some of my colleagues code the path of the mapped drive (on their workstation). Problem is, if you put the app on someone's workstation/computer it won't work unless they have the exact same mapping, which doesn't always work out. Am I looking at this the wrong way?

          ----------------------------- Just along for the ride. -----------------------------

          S Offline
          S Offline
          smcnulty2000
          wrote on last edited by
          #10

          On rare occasions I've seen software that won't work unless it goes through a mapped drive. That being said; I think Maxx's suggestion is the closest to what I'd go with. Don't forget: Include something to check if the shares is live. And then make sure to specify what happens when the share isn't- does it have a default? Does it halt with a specific error that is easy for the user to take the next step on? Does it flash a warning and proceed? I knew a guy who hard-coded elements like this into the compiled version of code. Guess why...He wanted them to come to him whenever there was a change. He hard-coded a password and rather than go to him they simply didn't bother to change the password.

          _____________________________ Give a man a mug, he drinks for a day. Teach a man to mug...

          S P 2 Replies Last reply
          0
          • S smcnulty2000

            On rare occasions I've seen software that won't work unless it goes through a mapped drive. That being said; I think Maxx's suggestion is the closest to what I'd go with. Don't forget: Include something to check if the shares is live. And then make sure to specify what happens when the share isn't- does it have a default? Does it halt with a specific error that is easy for the user to take the next step on? Does it flash a warning and proceed? I knew a guy who hard-coded elements like this into the compiled version of code. Guess why...He wanted them to come to him whenever there was a change. He hard-coded a password and rather than go to him they simply didn't bother to change the password.

            _____________________________ Give a man a mug, he drinks for a day. Teach a man to mug...

            S Offline
            S Offline
            Steve Mayfield
            wrote on last edited by
            #11

            hard-coded password computer security at it's finest :laugh:

            Steve _________________ I C(++) therefore I am

            modified on Wednesday, July 13, 2011 8:33 PM

            1 Reply Last reply
            0
            • S smcnulty2000

              On rare occasions I've seen software that won't work unless it goes through a mapped drive. That being said; I think Maxx's suggestion is the closest to what I'd go with. Don't forget: Include something to check if the shares is live. And then make sure to specify what happens when the share isn't- does it have a default? Does it halt with a specific error that is easy for the user to take the next step on? Does it flash a warning and proceed? I knew a guy who hard-coded elements like this into the compiled version of code. Guess why...He wanted them to come to him whenever there was a change. He hard-coded a password and rather than go to him they simply didn't bother to change the password.

              _____________________________ Give a man a mug, he drinks for a day. Teach a man to mug...

              P Offline
              P Offline
              Pualee
              wrote on last edited by
              #12

              smcnulty2000 wrote:

              On rare occasions I've seen software that won't work unless it goes through a mapped drive.

              SSIS for SQL Server 2005 comes to mind :mad:

              1 Reply Last reply
              0
              • S Slacker007

                We do a lot of in-house software and utilities that access network shares and servers. I usually code the path like so:

                \\MYSERVER001\SomeCrazyDirectory

                Some of my colleagues code the path of the mapped drive (on their workstation). Problem is, if you put the app on someone's workstation/computer it won't work unless they have the exact same mapping, which doesn't always work out. Am I looking at this the wrong way?

                ----------------------------- Just along for the ride. -----------------------------

                R Offline
                R Offline
                Rage
                wrote on last edited by
                #13

                Slacker007 wrote:

                the path of the mapped drive

                Mapping drives ? Are you stuck in 1995 ?

                1 Reply Last reply
                0
                • S Slacker007

                  We do a lot of in-house software and utilities that access network shares and servers. I usually code the path like so:

                  \\MYSERVER001\SomeCrazyDirectory

                  Some of my colleagues code the path of the mapped drive (on their workstation). Problem is, if you put the app on someone's workstation/computer it won't work unless they have the exact same mapping, which doesn't always work out. Am I looking at this the wrong way?

                  ----------------------------- Just along for the ride. -----------------------------

                  P Offline
                  P Offline
                  peterchen
                  wrote on last edited by
                  #14

                  Yours can be run by the scheduler, theirs - not. (At least, not so easily)

                  FILETIME to time_t
                  | FoldWithUs! | sighist | WhoIncludes - Analyzing C++ include file hierarchy

                  1 Reply Last reply
                  0
                  • A AspDotNetDev

                    Whatever you do, don't hard code it. I have had to deal with too many old servers over several jobs that can't be upgraded because somebody hardcoded a path rather than putting it into a configuration file or creating an options dialog that allows the user to change it. I would also avoid the mapping.

                    Driven to the ARMs by x86.

                    S Offline
                    S Offline
                    Slacker007
                    wrote on last edited by
                    #15

                    AspDotNetDev wrote:

                    Whatever you do, don't hard code it.

                    Only hard code it if I have to code VBA for older Office Automation apps, which unfortunately, we still have. Other than that it gets thrown into a config file and on very rare occasion it gets put into an .ini file. My question was more how do you approach the file path itself. :) [edit] if I can, I will put it into a database for Office stuff but that doesn't always work out.

                    ----------------------------- Just along for the ride. -----------------------------

                    J 1 Reply Last reply
                    0
                    • R Rutvik Dave

                      You are on right path, just want to point out one more thing, which you might be alreay doing here. please put those paths in app.config/web.config/database table so that you can change it without recompiling the app when network location changes. This will also solve the problem if you are not able to convince them to use network path, you can always change the path.

                      It's a shame that stupidity can't be converted into a usable energy source.

                      S Offline
                      S Offline
                      Slacker007
                      wrote on last edited by
                      #16

                      Rutvik Dave wrote:

                      please put those paths in app.config/web.config/database table

                      Always...when I can.

                      ----------------------------- Just along for the ride. -----------------------------

                      1 Reply Last reply
                      0
                      • S Slacker007

                        We do a lot of in-house software and utilities that access network shares and servers. I usually code the path like so:

                        \\MYSERVER001\SomeCrazyDirectory

                        Some of my colleagues code the path of the mapped drive (on their workstation). Problem is, if you put the app on someone's workstation/computer it won't work unless they have the exact same mapping, which doesn't always work out. Am I looking at this the wrong way?

                        ----------------------------- Just along for the ride. -----------------------------

                        P Offline
                        P Offline
                        PIEBALDconsult
                        wrote on last edited by
                        #17

                        I'm with you, mapping drives is soooo 90s. X| But still... on my last job I stored paths like your example in a configuration table and all was good... until the DNS went out. As a temporary solution I replaced the server names with the IP addresses. Eventually I wrote a little DNS service that periodically cached the IP addresses of the servers and then my code would replace the server name with the last known IP address on the fly.

                        1 Reply Last reply
                        0
                        • S Slacker007

                          We do a lot of in-house software and utilities that access network shares and servers. I usually code the path like so:

                          \\MYSERVER001\SomeCrazyDirectory

                          Some of my colleagues code the path of the mapped drive (on their workstation). Problem is, if you put the app on someone's workstation/computer it won't work unless they have the exact same mapping, which doesn't always work out. Am I looking at this the wrong way?

                          ----------------------------- Just along for the ride. -----------------------------

                          S Offline
                          S Offline
                          Steven O
                          wrote on last edited by
                          #18

                          I personally think that the UNC path (\\server\directory) is the way to go. I'll qualify this statement: If you wrote a service that needed to get files from a shared folder on the network, you must bear in mind that your service can run under different credentials to the logged on user, and as such may not have the same network drive mappings.

                          J 1 Reply Last reply
                          0
                          • S Steven O

                            I personally think that the UNC path (\\server\directory) is the way to go. I'll qualify this statement: If you wrote a service that needed to get files from a shared folder on the network, you must bear in mind that your service can run under different credentials to the logged on user, and as such may not have the same network drive mappings.

                            J Offline
                            J Offline
                            Jan Holst Jensen2
                            wrote on last edited by
                            #19

                            In principle the UNC path is the "right" way as it is supposed to be more stable than the mapped drive letter. However, in a corporate setting the reverse may be true. In that case all users will have a number of permanent drive letters mapped on logon. Central IT may change the server names when they move stuff around as they please but the drive letters stay put. I have worked for at least three companies where that is the case. So it ends up with the usual answer: "It depends" :) .

                            S 1 Reply Last reply
                            0
                            • J Jan Holst Jensen2

                              In principle the UNC path is the "right" way as it is supposed to be more stable than the mapped drive letter. However, in a corporate setting the reverse may be true. In that case all users will have a number of permanent drive letters mapped on logon. Central IT may change the server names when they move stuff around as they please but the drive letters stay put. I have worked for at least three companies where that is the case. So it ends up with the usual answer: "It depends" :) .

                              S Offline
                              S Offline
                              Steven O
                              wrote on last edited by
                              #20

                              I fully agree. I'll just say: It depends. :)

                              1 Reply Last reply
                              0
                              • S Slacker007

                                We do a lot of in-house software and utilities that access network shares and servers. I usually code the path like so:

                                \\MYSERVER001\SomeCrazyDirectory

                                Some of my colleagues code the path of the mapped drive (on their workstation). Problem is, if you put the app on someone's workstation/computer it won't work unless they have the exact same mapping, which doesn't always work out. Am I looking at this the wrong way?

                                ----------------------------- Just along for the ride. -----------------------------

                                M Offline
                                M Offline
                                Mark Eytcheson
                                wrote on last edited by
                                #21

                                Something to watch out for, depending on the client using the app - if the program is actually running on the machine that the UNC path is referencing, the local resource path cannot be accessed using UNC naming if the machine is set to use simple file sharing method to set file sharing permissions, at least not on XP. Took me a while to figure that one out.

                                OldDude

                                S 1 Reply Last reply
                                0
                                • M Mark Eytcheson

                                  Something to watch out for, depending on the client using the app - if the program is actually running on the machine that the UNC path is referencing, the local resource path cannot be accessed using UNC naming if the machine is set to use simple file sharing method to set file sharing permissions, at least not on XP. Took me a while to figure that one out.

                                  OldDude

                                  S Offline
                                  S Offline
                                  Slacker007
                                  wrote on last edited by
                                  #22

                                  Thanks for the tip. I did not know this.

                                  ----------------------------- Just along for the ride. -----------------------------

                                  1 Reply Last reply
                                  0
                                  • S Slacker007

                                    We do a lot of in-house software and utilities that access network shares and servers. I usually code the path like so:

                                    \\MYSERVER001\SomeCrazyDirectory

                                    Some of my colleagues code the path of the mapped drive (on their workstation). Problem is, if you put the app on someone's workstation/computer it won't work unless they have the exact same mapping, which doesn't always work out. Am I looking at this the wrong way?

                                    ----------------------------- Just along for the ride. -----------------------------

                                    P Offline
                                    P Offline
                                    PhilipOakley
                                    wrote on last edited by
                                    #23

                                    Always use a \\DNS_SERVER_NAME\directory\path. Never use a \\PhysicalServerName\It\will\be\replaced. Get your local DNS person to code the \\DNS_SERVER_NAME to \\PhysicalServerName mapping, so you can update everything at the one point. (I've had to have a local DNS entry that has to map a \\previous-company-name\hard-server-name to the latest virtual server!) Use the

                                    PathCopy4

                                    utility (use your favourite search engine!). It is wonderful for getting proper paths. It's also great for folks pasting proper paths into emails (wrap with <....> angle brackets for blanks in path \ file names in plain text emails)

                                    S 1 Reply Last reply
                                    0
                                    • P PhilipOakley

                                      Always use a \\DNS_SERVER_NAME\directory\path. Never use a \\PhysicalServerName\It\will\be\replaced. Get your local DNS person to code the \\DNS_SERVER_NAME to \\PhysicalServerName mapping, so you can update everything at the one point. (I've had to have a local DNS entry that has to map a \\previous-company-name\hard-server-name to the latest virtual server!) Use the

                                      PathCopy4

                                      utility (use your favourite search engine!). It is wonderful for getting proper paths. It's also great for folks pasting proper paths into emails (wrap with <....> angle brackets for blanks in path \ file names in plain text emails)

                                      S Offline
                                      S Offline
                                      Slacker007
                                      wrote on last edited by
                                      #24

                                      Thanks for the info Philip.

                                      ----------------------------- Just along for the ride. -----------------------------

                                      1 Reply Last reply
                                      0
                                      • C Chris Losinger

                                        Slacker007 wrote:

                                        Am I looking at this the wrong way?

                                        i vote : No

                                        image processing toolkits | batch image processing

                                        J Offline
                                        J Offline
                                        jesseseger
                                        wrote on last edited by
                                        #25

                                        I also vote NO. However, there is the case where you MOVE all of the shared data to another machine. If you used mapped drives, then all the user needs to do is remap. But I always lean towards using UNC.

                                        1 Reply Last reply
                                        0
                                        • S Slacker007

                                          AspDotNetDev wrote:

                                          Whatever you do, don't hard code it.

                                          Only hard code it if I have to code VBA for older Office Automation apps, which unfortunately, we still have. Other than that it gets thrown into a config file and on very rare occasion it gets put into an .ini file. My question was more how do you approach the file path itself. :) [edit] if I can, I will put it into a database for Office stuff but that doesn't always work out.

                                          ----------------------------- Just along for the ride. -----------------------------

                                          J Offline
                                          J Offline
                                          Julian Nicholls
                                          wrote on last edited by
                                          #26

                                          Once it's in an external configuration file, it no longer matters whether it's the mapped Q: drive or \\serverQ\share1 that's referenced because it can be changed without changing the software.

                                          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