how to download any type of files in asp.net mvc

how to download any type of files in asp.net mvc | c#
Action Method:

public FileResult DownloadFile()

{
    string path = Server.MapPath("~") + "/assets/FileInfo.zip";
    byte[] fileBytes = System.IO.File.ReadAllBytes(path);
    string fileName = "FileInfo.zip";
    return File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, fileName);
}

View:


<a href="@Url.Action("DownloadFile", "Home")"> Download File</a>

Post a Comment

0 Comments