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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Relative file path referencing problem

Relative file path referencing problem

Scheduled Pinned Locked Moved C#
helpcsharpquestion
6 Posts 2 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.
  • J Offline
    J Offline
    Jacobus01
    wrote on last edited by
    #1

    I need to change the default location that my application uses to reference files relatively. I use the syntax as follows: "..\\DBconnection.sec". This returns: C:\Projects\dotnet\RMS_IMCS\RMS_IMCS_WIN\bin\DBconnection.sec. I need the "bin" folder to be changed to RMS_IMCS. my relative reference needs to look like this: "..\\RMS_IMCS\\RMS_IMCS_WIN\bin\DBconnection.sec". This would allow me to chnage files located in folders outside my project without having to use absolute referencing. Any help?

    D 1 Reply Last reply
    0
    • J Jacobus01

      I need to change the default location that my application uses to reference files relatively. I use the syntax as follows: "..\\DBconnection.sec". This returns: C:\Projects\dotnet\RMS_IMCS\RMS_IMCS_WIN\bin\DBconnection.sec. I need the "bin" folder to be changed to RMS_IMCS. my relative reference needs to look like this: "..\\RMS_IMCS\\RMS_IMCS_WIN\bin\DBconnection.sec". This would allow me to chnage files located in folders outside my project without having to use absolute referencing. Any help?

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

      Jacobus01 wrote:

      my relative reference needs to look like this: "..\\RMS_IMCS\\RMS_IMCS_WIN\bin\DBconnection.sec"

      I would highly recommend building a fully qualified path to the file. Using relative paths is problematic because the CurrentDirectory for you app can change without you knowing it. So, get the fully qualified path to your executable, then use the methods in the Path class to manipulate that path to give you the one you want.

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

      J 1 Reply Last reply
      0
      • D Dave Kreskowiak

        Jacobus01 wrote:

        my relative reference needs to look like this: "..\\RMS_IMCS\\RMS_IMCS_WIN\bin\DBconnection.sec"

        I would highly recommend building a fully qualified path to the file. Using relative paths is problematic because the CurrentDirectory for you app can change without you knowing it. So, get the fully qualified path to your executable, then use the methods in the Path class to manipulate that path to give you the one you want.

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

        J Offline
        J Offline
        Jacobus01
        wrote on last edited by
        #3

        This is a hard thing to do. I have a solution in visual studio 2008 that contains multiple projects. Some are class libraries, some are web apps and some are win apps. Upon deployment I have no idea where all the apps will be located. They will however contain all their needed dlls in the bin folder. Not exactly sure where the web app will keep its dlls. This DBconnection.sec file contains an encrypted DB connection string. I decided to do this to avoid having to recompile the program if the connection string changes and it needs to be encrypted. Somehow my web application and win application needs to know where this file is located. I have a sub system that allows you to create this file but I'm unsure where to store it. How can I solve this issue and make this file available to both the win apps and web apps?

        D 1 Reply Last reply
        0
        • J Jacobus01

          This is a hard thing to do. I have a solution in visual studio 2008 that contains multiple projects. Some are class libraries, some are web apps and some are win apps. Upon deployment I have no idea where all the apps will be located. They will however contain all their needed dlls in the bin folder. Not exactly sure where the web app will keep its dlls. This DBconnection.sec file contains an encrypted DB connection string. I decided to do this to avoid having to recompile the program if the connection string changes and it needs to be encrypted. Somehow my web application and win application needs to know where this file is located. I have a sub system that allows you to create this file but I'm unsure where to store it. How can I solve this issue and make this file available to both the win apps and web apps?

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

          Each app is going to have it's own app.config for web.config. Class libraries don't get to use their own app.config. They use the config of the application that loads the .DLL. Since the web app is going to be the most restricted in navigating the file system, the connection string should go in it's web.config file. The other apps can have their own app.config file that has the file path to the web app and can retrieve the connection string from that. I don't know your situation entirely, but I would consider putting the connection string in each config file. I'm just thinking about production and test environments when you might want one or more app(s) might have a different connection string from the others for testing.

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

          J 1 Reply Last reply
          0
          • D Dave Kreskowiak

            Each app is going to have it's own app.config for web.config. Class libraries don't get to use their own app.config. They use the config of the application that loads the .DLL. Since the web app is going to be the most restricted in navigating the file system, the connection string should go in it's web.config file. The other apps can have their own app.config file that has the file path to the web app and can retrieve the connection string from that. I don't know your situation entirely, but I would consider putting the connection string in each config file. I'm just thinking about production and test environments when you might want one or more app(s) might have a different connection string from the others for testing.

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

            J Offline
            J Offline
            Jacobus01
            wrote on last edited by
            #5

            What about encryption? I dont want my client to see the connection string (or any other party for that matter).

            D 1 Reply Last reply
            0
            • J Jacobus01

              What about encryption? I dont want my client to see the connection string (or any other party for that matter).

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

              Your encrypting it now, right? It doesn't change. If your not, then Google for "encrypt connection string" for a ton of examples.

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

              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