محمد اشرف
محمد اشرف

Reputation: 59

How to convert Relative Path into absolute path in c#

I have stored Database in the main folder of my project, I am using Relative Path while i use that database. Now i need to convert this realtive path into absolute path at runtime I used tha following code but it doesnt work

string Path1 = @"Data Source=|DataDirectory|\MakeMyBill.sdf";
string fullpath=Path.GetFullPath(Path1);

Upvotes: 0

Views: 2216

Answers (2)

Yannis
Yannis

Reputation: 6157

You can do:

String absolutePath = Server.MapPath(myRelativePath);

Upvotes: 1

Deepak Saralaya
Deepak Saralaya

Reputation: 457

try like HostingEnvironment

string logDirectory = HostingEnvironment.MapPath("~") + "\\" + "App_Data\\MakeMyBill.sdf";

or

string logDirectory =Server.MapPath("~/App_Data/MakeMyBill.sdf")

or on any folder

     string filePath = @"D:\file\";
        string directoryName = Path.GetDirectoryName(filePath);
        filePath = directoryName + @"\file.xml";

Upvotes: 0

Related Questions