Convert asp.net webforms logic to asp.net MVC

Posted by gmcalab on Stack Overflow See other posts from Stack Overflow or by gmcalab
Published on 2010-05-17T17:44:10Z Indexed on 2010/05/17 17:51 UTC
Read the original article Hit count: 313

Filed under:
|

I had this code in an old asp.net webforms app to take a MemoryStream and pass it as the Response showing a PDF as the response. I am now working with an asp.net MVC application and looking to do this this same thing, but how should I go about showing the MemoryStream as PDF using MVC?

Here's my asp.net webforms code:

    private void ShowPDF(MemoryStream ms)
    {
        try
        {
            //get byte array of pdf in memory
            byte[] fileArray = ms.ToArray();
            //send file to the user
            Page.Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Page.Response.Buffer = true;
            Response.Clear();
            Response.ClearContent();
            Response.ClearHeaders();
            Response.Charset = string.Empty;
            Response.ContentType = "application/pdf";
            Response.AddHeader("content-length", fileArray.Length.ToString());
            Response.AddHeader("Content-Disposition", "attachment;filename=TID.pdf;");
            Response.BinaryWrite(fileArray);
            Response.Flush();
            Response.Close();
        }
        catch
        {
           // and boom goes the dynamite...
        }
    }

© Stack Overflow or respective owner

Related posts about itextsharp

Related posts about asp.net-mvc