Search code examples
c#asp.net-mvcpdfsharp

PDFSharp saving pdf to Content folder in ASP .NET MVC 5


I'm new to PDFSharp and I'm trying to save a PDF document, but when I call renderer.PdfDocument.Save(filename) it attempts to save it inside C:\Program Files\IIS Express\ and obviously it crashes out of denied permission.

How can I save the PDF document to /Content/ folder inside my MVC project?


Solution

  • Use a function like Server.MapPath to get the absolute path of the destination folder and pass that to the Save method.

    See also:
    https://stackoverflow.com/a/1268755/1015447