How can I download all the files in the array?

0

I have the following arrangement:

foreach (string Id in Arguments.SelectedValues)
{
    string temp = @"http://localhost:17277/blob.ashx?Pdf=o|" + Id;
    Result.NavigateUrl = @"http://localhost:17277/blob.ashx?Pdf=o|" + Id;
}

in which I access the BLOB where the file is located and download it.
When I execute it, the fix does bring all the IDs, but I only download the file from the last ID in the array.

What do I owe and how can I make it download all the selected ones?

    
asked by CarlosOro 12.08.2016 в 20:56
source

2 answers

1

Of course this happens because in each iteration of the for you are stepping on the previous data leaving only the last one assigned to navigate

If in a url you can define a list of Ids then you should join them and navigate to the end

 string Ids = string.Join("|", Arguments.SelectedValues);

 string temp = @"http://localhost:17277/blob.ashx?Pdf=o|" + Ids;

 Result.NavigateUrl = temp;

If you can separate each id with some character as I imagine is the | you could send several ids in the url to download the images, or imagine generate the pdf with the images of those Ids

    
answered by 13.08.2016 в 05:00
1

To download multiple files, you could do it in several ways, the first one will be to modify the handler so that it receives the ids to download, generate a zip and return it to download, another is that the current action returns a java script that contains all the urls to the handler, in a tags with the target="_blank" attribute, which for js you simulate the click so that the file download starts.

Example of js

<script>
   jQuery(function(){
      @foreach(var urlArchivo in ViewBag.Archivos)
      {
<text>
      $('body').append($('<a target="_black" href="@urlArchivo" class="archivo-descargar" style="display:none"></a>'));
<text>    
      }
      $(".archivo-descargar").click();
      $(".archivo-descargar").remove();

   });
</script>

In the case of zip, there are libraries like DotNetZip that make it easier to do a zip

    
answered by 17.11.2016 в 19:24