0

Given an url http://localhost:5000/UploadFolder/filename.pdf as a virtual path, i want to get the physical path name that is connected to the virtual directory that i've made.

enter image description here

how to read the files in physical path named "Uploads" from the given url? I'm using ASP NET CORE C# and Server.MapPath doesn't work. Is there any alternative to read the file?

stucknubie
  • 33
  • 6
  • Check this thread:[Get the local path of a file in a virtual directory](https://stackoverflow.com/questions/67529936/get-the-local-path-of-a-file-in-a-virtual-directory): The Server.MapPath don't really map in ASP.NET Core. URLs aren't inherently based on any directory structure. Each component has conventions that may map to directories, but this isn't something that can be generalized. What you can do, however, is establish a mapping service for translating the base path—and optionally querying IIS to retrieve those mappings dynamically. – Zhi Lv Mar 21 '22 at 06:06
  • Generally, in asp.net core the static file or upload file was stored in the wwwroot folder, you can get the folder via the [IWebHostEnvironment.WebRootPath](https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.hosting.iwebhostenvironment?view=aspnetcore-6.0), refer the following articles: [Static files in ASP.NET Core](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/static-files?view=aspnetcore-6.0). – Zhi Lv Mar 21 '22 at 06:10

0 Answers0