Anant Jain

Anant Jain

  • NA
  • 61
  • 8.3k

File Download in Database

Mar 28 2016 8:39 AM
When i upload a file  with his extension  file save in both database and his server path folder.
but when i create download controller this code -
 -------------------------------------------------------------------------------------------------------------------
public ActionResult Edit(int id = 0)
{
TrackMaster Task = db.TrackMasters.Find(id);
if (Task == null)
{
return HttpNotFound();
}
var p = (from x in db.TrackMasters where x.MastId == id select x.Path);
string xx =Convert.ToString(p);
string[] files = Directory.GetFiles(Server.MapPath("~/uploads"));
for (int i = 0; i < files.Length; i++)
{
files[i] = Path.GetFileName(files[i]);
}
ViewBag.Files = files;
return View(Task);
}
 -------------------------------------------------------------------------------------------------------
 And In view we write this code
 
 ---------------------------------------------------------------------------------------------------------
 
 
@{
var Files = (ViewBag.Files as string[]);
if (Files != null && Files.Any())
{
foreach (var file in Files)
{
<br />
@Html.ActionLink(file, "DownloadFile", new { fileName = file })
<br />
}
}
else
{
<label>No File(s) to Download</label>
}
}
 ------------------------------------------------------------------------------------------------------------------
 
The main problem is that in all file who saved in upload folder are show in download list
i want only those file who are attach with that recoad .so if any solution of this query

Answers (1)