Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Although you are looping over each file in the directory, once you do your Response.End() on the first iteration of the loop, the response to the user is done. They would only get the first file that is found by the enumerator.</p> <p>The browser doesn't have a concept of receiving multiple files in the way you are attempting.</p> <p>You may consider collecting the various image files and putting them together in a ZIP file, and then returning a single ZIP back to the user.</p> <p>Here is example code that will build a ZIP (using SharZipLib) of the images and reply with a single file called "images.zip"</p> <p>Include these using statements for SharpZipLib:</p> <pre><code>using ICSharpCode.SharpZipLib.Core; using ICSharpCode.SharpZipLib.Zip; using ICSharpCode.SharpZipLib.Checksums; </code></pre> <p>Then in the method where you want to stream back the ZIP file:</p> <pre><code>DirectoryInfo directoryInfo = new DirectoryInfo(Server.MapPath(@"/Bailiffs/BailiffFiles/")); string cukurNumber = string.Empty; if (txtCukurNumber.Text != string.Empty) { cukurNumber = txtCukurNumber.Text; } IEnumerable&lt;FileInfo&gt; fileInfoEnum = directoryInfo.EnumerateFiles( cukurNumber + "*" ); Response.Clear(); Response.AddHeader( "Content-Disposition", "attachment;filename=images.zip" ); Response.ContentType = "application/zip"; using( ZipOutputStream zipstream = new ZipOutputStream( Response.OutputStream ) ) { zipstream.SetLevel( 9 ); // 0-9, 9 being the highest compression byte[] buffer = new byte[4096]; foreach( FileInfo fileInfo in fileInfoEnum ) { string file = fileInfo.FullName; ZipEntry entry = new ZipEntry( Path.GetFileName( file ) ); entry.DateTime = DateTime.Now; zipstream.PutNextEntry( entry ); using( FileStream fs = File.OpenRead( file ) ) { int sourceBytes; do { sourceBytes = fs.Read( buffer, 0, buffer.Length ); zipstream.Write( buffer, 0, sourceBytes ); } while( sourceBytes &gt; 0 ); } } zipstream.Finish(); zipstream.Close(); } Response.Flush(); Response.End(); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload