Downloading one file at a time

DikongPrigm 61 Reputation points

How do you guys usually approach this. I'm trying to request a file from the server. The server will then process the file for me and it may take some time to process the file I am requesting for. While the server still process the file, I might want to request another one. This will then enque the request after the previous one.

Let me know your thoughts.

A set of technologies in the .NET Framework for building web applications and XML web services.
3,789 questions
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
9,505 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Zhi Lv - MSFT 28,256 Reputation points Microsoft Vendor

    Hi @DikongPrigm ,

    I use an API endpoint to return a file, then I use the <a> tag to display the download button, and after clicking the download button, the server side process the file, after that it downloads the file. By using this method, after clicking the download button, I don't need to wait for the download finished, I can click the download button multiple times, then it will download the file one by one.

    Refer to the following sample code:

    To download file from the file folder

    public class ToDoController : ControllerBase  
        private readonly IWebHostEnvironment environment;  
        public ToDoController(IWebHostEnvironment hostEnvironment)  
            environment = hostEnvironment;  
        public IActionResult Download()  
            var filepath = Path.Combine(environment.WebRootPath, "images", "Image1.png");  
            return File(System.IO.File.ReadAllBytes(filepath), "image/png", System.IO.Path.GetFileName(filepath));  

    Then, in the Index view page, we can add a hyperlink to call this API method and download file:

    <a href='~/api/Todo/download' download>Download File From Folder</a>  

    More detail information, see my reply in this thread: Download file in C# .Net Core

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best regards,

    0 comments No comments