开发者

XML Parseing Error when serving a PDF

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 configurati开发者_如何学JAVAon/whatever) to get my pdf file to load?


The query string does not look right:

https://ucc489/rc/NoteFileHandler.ashx?noteId=1,msdsId=3

Surely ?noteId=1,msdsId=3 should be noteId=1&msdsId=3. I don't know if this is related to the XML error, but it is the first thing that strikes me as wrong.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜