Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I convert a relative path to a fully qualified path in C# / .NET?

Let's say I have a file name defined as "..............\bin\prices.xls", is there a simple way to convert that to a fully qualified path (one that includes the Drive letter, colon and all folders to the file)?

like image 817
Bernhard Hofmann Avatar asked Jan 29 '10 13:01

Bernhard Hofmann


People also ask

How do you convert relative path to absolute path?

The absolutePath function works by beginning at the starting folder and moving up one level for each "../" in the relative path. Then it concatenates the changed starting folder with the relative path to produce the equivalent absolute path.

How do I get a full file path?

Click the Start button and then click Computer, click to open the location of the desired file, hold down the Shift key and right-click the file. Copy As Path: Click this option to paste the full file path into a document. Properties: Click this option to immediately view the full file path (location).

What is a fully qualified file path?

A fully qualified path or absolute path always defines an exact path from a particular drive or device to a target file or directory, and does not depend on the current drive or current directory.

What is the difference between a full and relative path name?

In simple words, an absolute path refers to the same location in a file system relative to the root directory, whereas a relative path points to a specific location in a file system relative to the current directory you are working on.


1 Answers

Try Path.GetFullPath():

Returns the absolute path for the specified path string.

The absolute path includes all information required to locate a file or directory on a system.

like image 168
Anton Gogolev Avatar answered Nov 10 '22 07:11

Anton Gogolev