Reputation: 5458
I've been trying to open a file in asp.net 5 and have not been having a lot of success.
In the past you used Server.MapPath
or HostingEnvironment.ApplicationPhysicalPath
. They are both gone in the OWIN based framework.
There is a HostingEnvironment
class but it's in the System.Aspnet
but it needs to be initialized by the hosting environment (it no longer has a static member for ApplicationPhysicalPath
but I'm guessing the WebRoot
member does that now. The problem is I can't find a reference to it anywhere.
I've also looked at Context.GetFeature<>
but it doesn't seem to have any feature that would show the application path, just request and response related info. The code listing the features can be found here.
<snark>
Is the ability to work with files a discontinued feature in ASP.NET?</snark>
There is also the possibility that I can't brain very well right now and missed something.
Upvotes: 9
Views: 7764
Reputation: 141434
There are two approaches now:
using Microsoft.Extensions.PlatformAbstractions;
public Startup(IApplicationEnvironment appEnv)
{
// approach 1
var path01 = PlatformServices.Default.Application.ApplicationBasePath;
// approach 2
var path02 = appEnv.ApplicationBasePath;
}
Upvotes: 6
Reputation: 57939
You can get it from the ApplicationBasePath
property of Microsoft.Framework.Runtime.IApplicationEnvironment
serivce.
Upvotes: 12