How to retrieve PDF File with download link in MVC
I am trying to create an application with fileupload control and i have saved the image path in datbase.
but i want that i should have a list with download option for the uploaded file in database.
I have already seen the link from aspforums and aspsnippets but they were not able to solve my problem
its a request if u can solve my issue instead of providing link
thank you
namespace ReportManagement.Controllers
{
public class MeetingEntryController : Controller
{
// GET: MeetingEntry
public ActionResult ViewFiles(int id)
{
using(ApplicationDbContext db=new ApplicationDbContext())
{
var pdffile = db.MeetingDetails.Where(x => x.id == id).FirstOrDefault();
}
return View();
}
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(MeetingDetail ms)
{
//string path = Server.MapPath("~/App_Data/File");
string filename = Path.GetFileNameWithoutExtension(ms.file.FileName);
string extension = Path.GetExtension(ms.file.FileName);
filename = filename + DateTime.Now.ToString("yymmssfff") + extension;
//string fullpath = Path.Combine(path, filename);
ms.filepath = "~/App_Data/File" + filename;
filename = Path.Combine(Server.MapPath("~/App_Data/File"), filename);
ms.file.SaveAs(filename);
//ms.UserName = "User1";
using (ApplicationDbContext db=new ApplicationDbContext())
{
ms.id = 1;
db.MeetingDetails.Add(ms);
db.SaveChanges();
}
ModelState.Clear();
return View();
}
}
}
@model ReportManagement.Models.MeetingDetail
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
@using (Html.BeginForm("Index","MeetingEntry",FormMethod.Post,new {enctype="multipart/form-data" }))
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>MeetingDetail</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.Label("Upload Meeting PDF", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
<input type="file" name="file" />
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.UserName, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.UserName, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.UserName, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}