Get List of hyperlinks to files from a folder [Resolved]

Posted by Rasagna under ASP.NET MVC on 4/5/2016 | Points: 10 | Views : 1771 | Status : [Member] | Replies : 1
I have to display hyperlinks to view the pdf file along with name in a grid.
I have tried the following code but of no use.please suggest some solution.thanks in advance.
My controller code:
   public ActionResult Index()
string[] filesPath = Directory.GetFiles(Server.MapPath("~/MyPdfs"), "*.pdf");
StringBuilder sb = new StringBuilder();
List<FileInfo> files = new List<FileInfo>();
foreach (string path in filesPath)
files.Add(new FileInfo(Path.GetFileName(path)));
return View(files);

My View Code

@model IEnumerable<FileInfo>
ViewBag.Title = "Home Page";

<table class="grid">
@foreach (FileInfo file in Model)
<td class="left">@file.Name</td>
<td class="left">@file.Extension</td>
<a href="@file" target="_blank">
<img src="@Url.Content("~/Content/Images/Image.png")" alt="Edit" />



Posted by: Rasagna on: 4/5/2016 [Member] Starter | Points: 25


Found solution for my problem

<a href="@Url.Content("~/MyPdfs/" + System.IO.Path.GetFileName(@file.Name))" target="_blank">
<img src="@Url.Content("~/Content/Images/Image.png")"/>

Rasagna, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response