0

i have following action not return a View

  public FileResult Download(int? id)
    {
        var files = from p in _db.tbl_Pdfs
                    where p.PaperId == id
                    select p.FileName;

        var archive = Server.MapPath("~/Content/Zip/archive.zip");
        var temp = Server.MapPath("~/Content/Temp");

        // clear any existing archive
        if (System.IO.File.Exists(archive))
        {
            System.IO.File.Delete(archive);
        }
        // empty the temp folder
        Directory.EnumerateFiles(temp).ToList().ForEach(f => System.IO.File.Delete(f));

        // copy the selected files to the temp folder

        foreach (string name in files)
        {
            string sourceFile = System.IO.Path.Combine("~/Content/Pdf", name);
            System.IO.File.Copy(sourceFile, "~/Content/Temp", true);
        }
        // create a new archive
        ZipFile.CreateFromDirectory(temp, archive, CompressionLevel.Fastest, true);



        return File(archive, "application/zip", "archive.zip");
    }

and also have following link for download zip file

<a href="~/Home/Download/@ViewBag.id" class="btn">Download zip</a>

i also change it to the following linkis

   @Html.ActionLink("Download zip", "Download", new { id=@ViewBag.id, @class = "btn" })

 <a href="@Url.Action("download","Home" , new { id=@ViewBag.id})" class="btn"> Download zip</a>

But still gives an error !

The resource cannot be found.

Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

Requested URL: /Home/Download/7

what should i do? it this error case the action not return a view?

mina a.beigi
  • 122
  • 3
  • 13
  • Does the `Download()` method does not exist in `HomeController`? –  May 02 '16 at 05:17
  • @StephenMuecke Of course exist! i think it because of the result type and When the error occurs that does not find relevant view but i don't know how to fix it ! i don't need a view for action! – mina a.beigi May 02 '16 at 05:23
  • 1
    The error is telling you it doesn't exist. Are you using areas at all (it has nothing to do with the 'result type') –  May 02 '16 at 05:25
  • @StephenMuecke no i'm not using areas! – mina a.beigi May 02 '16 at 05:29

1 Answers1

0

can you please change the following and try

foreach (string name in files)
{
    string sourceFile = Server.MapPath( System.IO.Path.Combine("~/Content/Pdf", name));
    System.IO.File.Copy(sourceFile, Server.MapPath(System.IO.Path.Combine("~/Content/Temp", name)), true);
}
  • What possible difference could changing the code make when the method is never hit! –  May 02 '16 at 23:34