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. Relative file path

Relative file path

Scheduled Pinned Locked Moved C#
questiongraphics
2 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.
  • S Offline
    S Offline
    Stephane David
    wrote on last edited by
    #1

    In my application, I want the user to be able to customize the path to some files. So I use a OpenFileDialog, and get the path of the new file, and I can open the file. I'd like to store the path for the next use of the program, but I want to store it relatively to my executable. But the OpenFileDialog return the absolute path. So if I have: e:\Programs\MyProgram\Bin\MyExecutable.exe and the user select e:\Programs\MyPrograms\Graphics\MyFile.gif How can I easily find that the path to store is ..\Graphics\MyFile.gif?

    J 1 Reply Last reply
    0
    • S Stephane David

      In my application, I want the user to be able to customize the path to some files. So I use a OpenFileDialog, and get the path of the new file, and I can open the file. I'd like to store the path for the next use of the program, but I want to store it relatively to my executable. But the OpenFileDialog return the absolute path. So if I have: e:\Programs\MyProgram\Bin\MyExecutable.exe and the user select e:\Programs\MyPrograms\Graphics\MyFile.gif How can I easily find that the path to store is ..\Graphics\MyFile.gif?

      J Offline
      J Offline
      Jim Stewart
      wrote on last edited by
      #2

      In shlwapi.dll there is a method called PathRelativePathTo.

      α.γεεκ

      Fortune passes everywhere.
      Duke Leto Atreides

      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