XML Parseing Error when serving a PDF
- by Andy
I'm trying to serve a pdf file from a database in ASP.NET using an Http Handler, but every time I go to the page I get an error
XML Parsing Error: no element found
Location: https://ucc489/rc/NoteFileHandler.ashx?noteId=1,msdsId=3
Line Number 1, Column 1:
^
Here is my HttpHandler code:
public class NoteFileHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
if (context.Request.QueryString.HasKeys())
{
if (context.Request.QueryString["noteId"] != null && context.Request.QueryString["msdsId"] != null)
{
string nId = context.Request.QueryString["noteId"];
string mId = context.Request.QueryString["msdsId"];
DataTable noteFileDt = App_Models.Notes.GetNoteFile(nId, mId);
if (noteFileDt.Rows.Count > 0)
{
try
{
context.Response.Clear();
context.Response.AddHeader("content-disposition", "attachment;filename=" +
noteFileDt.Rows[0][0] + ".pdf");
context.Response.ContentType = "application/pdf";
byte[] file = (byte[])noteFileDt.Rows[0][1];
context.Response.BinaryWrite(file);
context.Response.End();
}
catch
{
context.Response.ContentType = "text/plain";
context.Response.Write("File Not Found");
context.Response.StatusCode = 404;
}
}
}
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
Is there anything else I need to do (server configuration/whatever) to get my pdf file to load?