I have a directory C:\Source\SomeDirectory\
that has any number of .pdf
and .txt
files. I need to display these files on my ASP.NET web page and have each one of them be downloadable links e.g.:
Where each one of these is either a .pdf or .txt.
How can I create links for every single one of these files? I know they will all be in the same directory. I have tried things like Returning a file to View/Download in ASP.NET MVC but this only returns one file?
Instead, I need to return a bunch of downloadable files and have links for them on my page among other normal HTML elements. How can I achieve this?
Edit: I have already written code that utilizes DirectoryInfo(path).GetFiles()
to get a list of those files. I store the each fileName
and its filePath
into a list of objects in my viewmodel and pass that into my view. Can I use these attributes as parameters to make the download happen?
It is displayed like:
<ul>
<li><a href="@FileList[0].Path"><@FileList[0].FileName</a></li>
<li><a href="@FileList[1].Path"><@FileList[1].FileName</a></li>
<li><a href="@FileList[2].Path"><@FileList[2].FileName</a></li>
</ul>