user6269870
user6269870

Reputation:

How to find absolute path using a relative path in c#

I have a path stored in a variable say

string partialPath = '\editors\tinymce' 

I want to get the entire path of the above fie. The actual path of the above file is 'D:\Back up\editors\tinymce'. How can I do this in C#. Thanks

Upvotes: 0

Views: 448

Answers (3)

kkakadiya
kkakadiya

Reputation: 61

please try with below code:

code:

string partialPath = "\editors\tinymce";
var output = Server.MapPath(partialPath);
string str = HttpContext.Current.Server.MapPath(partialPath);

you can get path on output var and str string.

let us know.

Upvotes: 0

Mohit S
Mohit S

Reputation: 14024

This might do the trick for you

string partialPath = "\editors\tinymce";
string fullPath = Path.GetFullPath(partialPath);

output:

D:\editors\tinymce

Whereas

This might do the trick for you

string partialPath = "editors\tinymce";
fullPath = Path.GetFullPath(partialPath);

output:

D:\Back up\editors\tinymce

Upvotes: 3

David
David

Reputation: 16277

var dir = Directory.GetCurrentDirectory();
var output = Path.Combine(dir, partialPath);

Upvotes: 3

Related Questions