TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
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
Reply
Answers (
1
)
Using sql query show data in grid view
MVC