Gab
Gab

Reputation: 1920

Get local file path in asp.net mvc website

I have a solution with two projects : a asp.net mvc website, and a class library. In the website, I have a reference to the class library.

In a method of the class library I need to get the path of a file in my website project (a config file).

I tried :

HostingEnvironment.ApplicationPhysicalPath

This works but I can't unit test it... Do you have a simple solution for unit tests or an other way to get the path I need ?

I also tried :

System.Reflection.Assembly.GetAssembly(typeof(MyClass)).Location;

But I get :

C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\.....

What can I use ?

Upvotes: 2

Views: 9464

Answers (1)

Gab
Gab

Reputation: 1920

This code did the trick :

HttpContext.Current.Server.MapPath("~")

Upvotes: 6

Related Questions