For those just wanting to return an existing Zip file from the App_Data folder (just dump in your zip files there), in the Home controller create this action method:
public FileResult DownLoad(string filename)
{
var content = XFile.GetFile(filename);
return File(content, System.Net.Mime.MediaTypeNames.Application.Zip, filename);
}
Get File is an extention method:
public static byte[] GetFile(string name)
{
string path = AppDomain.CurrentDomain.GetData("DataDirectory").ToString();
string filenanme = path + "/" + name;
byte[] bytes = File.ReadAllBytes(filenanme);
return bytes;
}
Home controller Index view looks like this:
@model List<FileInfo>
<table class="table">
<tr>
<th>
@Html.DisplayName("File Name")
</th>
<th>
@Html.DisplayName("Last Write Time")
</th>
<th>
@Html.DisplayName("Length (mb)")
</th>
<th></th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.ActionLink("DownLoad","DownLoad",new {filename=item.Name})
</td>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.LastWriteTime)
</td>
<td>
@Html.DisplayFor(modelItem => item.Length)
</td>
</tr>
}
</table>
The main index file action method:
public ActionResult Index()
{
var names = XFile.GetFileInformation();
return View(names);
}
Where GetFileInformation is an extension method:
public static List<FileInfo> GetFileInformation()
{
string path = AppDomain.CurrentDomain.GetData("DataDirectory").ToString();
var dirInfo = new DirectoryInfo(path);
return dirInfo.EnumerateFiles().ToList();
}