0

i'm tying to make DL link so others couldn't dl the same file by sharing it so far i've found this code

public FileResult Download()
{
    byte[] fileBytes = System.IO.File.ReadAllBytes(@"c:\folder\myfile.ext");
    string fileName = "myfile.ext";
    return File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, fileName);
}

it won't make interchangeable links ,how can we do that?

Mostafa Bouzari
  • 9,207
  • 3
  • 16
  • 26

1 Answers1

1

Try this Example:

public ActionResult Download()
{
    var filePath=@"c:\folder\myfile.ext";
    var fileBytes = System.IO.File.ReadAllBytes(filePath);
    var response = new FileContentResult(fileBytes, "application/octet-stream")
    {
        FileDownloadName = Path.GetFileName(filePath)
    };
    return response;
}
Ashiquzzaman
  • 5,129
  • 3
  • 27
  • 38