In ASP.NET, I have used the Server.MapPath()
method to get the physical path. Now in core, I can't do that, I have used IHostingEnvironment
, but it can only get wwwroot
path.
Asked
Active
Viewed 5,658 times
3
-
I look some article ,this [link](https://stackoverflow.com/questions/40562149/can-not-access-virtual-directory-under-virtual-dotnet-core-api-application-on-ii) make me know how to solve the quesion. – willim Aug 22 '17 at 01:52
-
https://stackoverflow.com/a/55380851/7149454 – Nick Kovalsky Mar 27 '19 at 15:26
1 Answers
0
You should use FileProvider
var contents = _fileProvider.GetDirectoryContents("");
return contents.Select(i => i.PhysicalPath);
You can check out my demo code

Alex Nguyen
- 1,032
- 12
- 27
-
I have already try,it's a get file list from a directory ,Not to get physic path – willim Aug 21 '17 at 08:41
-
you can get the physical path by its property = PhysicalPath contents.Select(i => i.PhysicalPath); => it returns the physical path – Alex Nguyen Aug 21 '17 at 08:43
-
I publish a website in IIS,and set a directory to virtual directory.Now I want to get the directory physic path to save file. – willim Aug 21 '17 at 08:45
-
-
inject IHostingEnvironment in your controller and then you can get your root path, var rootPath =_env.ContentRootPath; – Alex Nguyen Aug 21 '17 at 09:06
-
-
i' sorry,it seem is not a good method.Now I write the physical path to appsetting to resolve this problem .Look forward to better method . How ever ,I'm still thank you very much! – willim Aug 21 '17 at 09:35