Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert a relative path to an absolute path in a Windows application?

Tags:

c#

How do I convert a relative path to an absolute path in a Windows application?

I know we can use server.MapPath() in ASP.NET. But what can we do in a Windows application?

I mean, if there is a .NET built-in function that can handle that...

like image 707
Amit Dhall Avatar asked Sep 09 '09 11:09

Amit Dhall


People also ask

How do I create an absolute path in Windows?

You can determine the absolute path of any file in Windows by right-clicking a file and then clicking Properties. In the file properties first look at the "Location:" which is the path to the file. In the picture below, the location is "c:\odesk\computer_hope".

Can absolute path and relative path be the same?

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.

What is the equivalent to absolute path?

An absolute path is defined as specifying the location of a file or directory from the root directory(/). In other words,we can say that an absolute path is a complete path from start of actual file system from / directory. Relative path is defined as the path related to the present working directly(pwd).


1 Answers

Have you tried:

string absolute = Path.GetFullPath(relative); 

? Note that that will use the current working directory of the process, not the directory containing the executable. If that doesn't help, please clarify your question.

like image 168
Jon Skeet Avatar answered Sep 28 '22 04:09

Jon Skeet