How can I open a pdf file directly in my browser?

后端 未结 7 523
陌清茗
陌清茗 2020-12-25 15:14

I would like to view a PDF file directly in my browser. I know this question is already asked but I haven\'t found a solution that works for me.

Here is

7条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-25 15:49

    If you read the file stored in database image column, you can use like this:

    public ActionResult DownloadFile(int id)
    {
        using (var db = new DbContext())
        {
            var data =
                db.Documents.FirstOrDefault(m => m.ID == id);
            if (data == null) return HttpNotFound();
            Response.AppendHeader("content-disposition", "inline; filename=filename.pdf");
            return new FileStreamResult(new MemoryStream(data.Fisier.ToArray()), "application/pdf");
        }
    }
    

提交回复
热议问题