none
How to get Full Path from Relative Path ?

Answers

All replies

  •  thukralz wrote:

     

    I was wondering what is the way to get Full Path from Relative Path ?

     

    say I have "\\Test\\More Test";

     

     

    System.IO.Path.GetFullPath

    Wednesday, February 06, 2008 2:35 AM
  • Directory.GetParent

     

    Wednesday, February 06, 2008 2:44 AM
  • System.IO.Path.GetFullPath()  returns absolte path for the specified path string.

     

    Wednesday, February 06, 2008 2:49 AM
  •  thukralz wrote:

     

    I was wondering what is the way to get Full Path from Relative Path ?

     

    say I have "\\Test\\More Test";

     

     

    I swear I already answered this, but here goes:

     

    System.IO.Path.GetFullPath

     

     

    Wednesday, February 06, 2008 3:53 AM
  •  thukralz wrote:

    Directory.GetParent

     

     

    How is that an answer?  I'm confused.  GetParent doesn't do anything like what you asked about.

    Wednesday, February 06, 2008 3:56 AM
  • Use Path.GetFullPath();

    See this for more details: http://msdn2.microsoft.com/en-us/library/system.io.path.aspx

    Never mind. Others have already answered.
    Wednesday, February 06, 2008 8:44 AM
  • I know I replied to this thread. Why can't see my reply?
    Wednesday, February 06, 2008 8:50 AM
  •  

    It's relative to something. If you know that something you just take that something and append the relative path to it.

    If you don't know that something, there's no way to reconstruct it.

     

    Wednesday, February 06, 2008 9:35 AM
  •  

    interesting, replies to many posts only show up after you post your own reply (and when reloading the post they're gone again until you post a new reply it seems).

     

    Buggy forum software? I'd half expect such behaviour from Sun's forums, MSDN seems better behaved usually

    Wednesday, February 06, 2008 9:39 AM
  • Hi,

    Path.GetFullPath will help you with that.

    Code Snippet

    Path.GetFullPath(@"..\..\Properties")

     


    Hope this helps.

    Wednesday, February 06, 2008 10:42 AM
  • There seems to be a bug in the forums that makes it look like no-one has answered this thread, until you actually reply to it.
    Then you can see loads of replies all saying Path.GetFullPath().

    Smile
    Wednesday, February 06, 2008 11:23 AM
  •  

    i guess this will work for you

     

    FileInfo finfo = new FileInfo(@"../../MicrosoftLink.txt");

    Console.WriteLine("Full name of the file is ----> {0}", finfo.FullName);

     

     

    Wednesday, February 06, 2008 11:25 AM
  • And alternatively...

     

    using System.Reflection;

    using System.IO;

     

    string path = Assembly.GetExecutingAssembly().Location;

    System.IO.FileInfo fi = new System.IO.FileInfo(path);

    _ProgramFolder = fi.DirectoryName;

    _ProgramName = fi.Name.Substring(0, fi.Name.Length - fi.Extension.Length);

     

    You can use the Path class to do the analysis and append whatever you want.

    Wednesday, February 06, 2008 1:09 PM
  • I wondered what was happening - I went thru the process twice.

    Wednesday, February 06, 2008 1:10 PM
  • You can't because there's no way to know where Test is in the filesystem hierarchy.
    I guess you could search for it, but that will take a long time.
    Wednesday, February 06, 2008 2:05 PM
  • I tried this code but when the application is run in debugging mode, it only seems to find the directory if it is listed in the root drive.  It occasionally returns non-existent paths.

    example:  I have created the following directory structure on my flash drive(FAT32, using Windows XP pro, autoplay enabled): F:\redintdirswall\ethernet\ , which I can browse to using windows explorer.

    In my application I am using something like the following code to return the full path for a file in the directory(the filename has no extension):

    System.IO.FileInfo finfo = new System.IO.FileInfo(@"..\..\redintdirswall\red\local-ipaddress");

    but rather than returning the correct path, it returns the following:

    C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\Smoothwall Manager\Smoothwall Manager\redintdirswall\red\local-ipaddress

    This may be a noob question, as I have just started c#, but how do I tell System.IO.FileInfo to return this directory structure on my flashdrive, bearing in mind that the drive letter will be variable at runtime?  I know how to do it using command prompt.
    Monday, August 10, 2009 11:25 PM
  • I tried this code but when the application is run in debugging mode, it only seems to find the directory if it is listed in the root drive.  It occasionally returns non-existent paths.

    example:  I have created the following directory structure on my flash drive(FAT32, using Windows XP pro, autoplay enabled): F:\redintdirswall\ethernet\ , which I can browse to using windows explorer.

    In my application I am using something like the following code to return the full path for a file in the directory(the filename has no extension):

    System.IO.FileInfo finfo = new System.IO.FileInfo(@"..\..\redintdirswall\red\local-ipaddress");

    but rather than returning the correct path, it returns the following:

    C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\Smoothwall Manager\Smoothwall Manager\redintdirswall\red\local-ipaddress

    This may be a noob question, as I have just started c#, but how do I tell System.IO.FileInfo to return this directory structure on my flashdrive, bearing in mind that the drive letter will be variable at runtime?  I know how to do it using command prompt.
    It's returning the correct value. It works out what the folder name is from the current working directory. That's where it starts from when it computes the full path of a relative pathname. See http://msdn.microsoft.com/en-us/library/system.io.directory.getcurrentdirectory.aspx
    Tuesday, August 11, 2009 12:07 AM
  • And alternatively...

     

    using System.Reflection;

    using System.IO;

     

    string path = Assembly.GetExecutingAssembly().Location;

    System.IO.FileInfo fi = new System.IO.FileInfo(path);

    _ProgramFolder = fi.DirectoryName;

    _ProgramName = fi.Name.Substring(0, fi.Name.Length - fi.Extension.Length);

     

    You can use the Path class to do the analysis and append whatever you want.

    thanks for your code

    Wednesday, January 05, 2011 12:29 AM
  • This is what the method Path.Combine is good for.  It returns a valid full path or an empty string.  It can also resolve relative paths into full paths.
    Mark the best replies as answers. "Fooling computers since 1971."

    http://rudedog2.spaces.live.com/default.aspx

    Wednesday, January 05, 2011 12:44 AM
    Moderator