Printing a PDF in a folder which is in wwwroot directory .net 5.0 web application

547 Views Asked by At

I have a folder structure as follows, please see 1st screenshot.

enter image description here

And this is my code so far.

enter image description here

I want to print the indicated PDF document. It works perfectly on my local development machine, but after uploading of site, it tanks. So I am not building the path correctly for web printing it seems? Thanks Luke

1

There are 1 best solutions below

0
On

As far as I know, if you want to access the wwwroot inside the controller, you could try to use IWebHostEnvironment's WebRootPath.

Codes:

    private readonly ILogger<HomeController> _logger;
    private IWebHostEnvironment Environment;

    public HomeController(ILogger<HomeController> logger, IWebHostEnvironment _environment)
    {
        _logger = logger;
        Environment = _environment;

    }

    public IActionResult Index()
    {

        string contentPath = this.Environment.WebRootPath;

        return View();
    }

Result:

enter image description here