Wednesday, April 27, 2016

HttpHandler for PDFs resolve static item

In an implementation I had created an HttpHandler which was used to find PDF files. However there was an edge case where it was handling files in a virtual folder (used by Sitecore for Print Experience Manager Publishing) and this was not desired logic.

The following line of code can be used to return the physical PDF (and not one from my handler):
context.Response.Clear();
context.Response.ContentType = "application/pdf";
context.Response.TransmitFile(context.Request.PhysicalPath);

context.Response.Flush();
context.Response.Close();
It will also 404 if the PDF does not exist on the path.

No comments:

Post a Comment