I've created a virtual directory in IIS, and I have a file that I want to get - like example.pdf. How do I get the virtual directory path and read the file in bytes? server.MapPath doesn't work in ASP.NET Core, and I didn't save the file in the wwwroot, I saved it to a folder Uploads outside the project, so I can't combine it with ContentRootPath or WebRootPath.
Can someone help me with this?
Currently my code is like this:
var path = "D:/FolderOutsideProjects/Uploads/filename.pdf";
var bytes = await System.IO.File.ReadAllBytesAsync(path);
return File(bytes, contentType, Path.GetFileName(path));
Thanks
There is no native way for ASP.NET Core to resolve the Virtual Directory path. You could potentially read the IIS configuration file, but that seems very complicated.
The easy solution will just be adding your directory path to appsettings.json instead.