Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6248069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:59:23+00:00 2026-05-24T12:59:23+00:00

ive got a file download issue can you help me for that… here is

  • 0

ive got a file download issue can you help me for that…

here is the code:

    DirectoryInfo directoryInfo = new DirectoryInfo(Server.MapPath(@"/Bailiffs/BailiffFiles/"));
        string cukurNumber = string.Empty;
        if (txtCukurNumber.Text != string.Empty) {
            cukurNumber = txtCukurNumber.Text;
        }
        FileInfo[] fileInfoEnum = directoryInfo.GetFiles(cukurNumber + "*");
        Response.Clear();
        Response.AddHeader("Content-Disposition", "attachment;filename=" + txtCukurNumber.Text + ".zip");            
        Response.ContentType = "application/zip";
        using (ZipOutputStream zipStream = new ZipOutputStream(Response.OutputStream)) {
            zipStream.SetLevel(9);
            byte[] zipBuffer = new byte[4096];

            foreach (FileInfo fileInfo in fileInfoEnum) {
                string fileFullName = fileInfo.FullName;

                ZipEntry zipEntry = new ZipEntry(Path.GetFileName(fileFullName));

                zipEntry.DateTime = DateTime.Now;

                zipStream.PutNextEntry(zipEntry);

                using (FileStream fileStream = File.OpenRead(fileFullName)) {
                    int sourceBytes = 0;
                    do {
                        sourceBytes = fileStream.Read(zipBuffer, 0, zipBuffer.Length);
                        zipStream.Write(zipBuffer, 0, sourceBytes);
                    } while (sourceBytes > 0);


                }                    
            }
            zipStream.Finish();
            zipStream.Close();
            Response.Flush();
            Response.End();
        }

this code must be get all image files by filter and save to disk but save file dialog of browser is opening just one time and one bizarre file is saving… where am i doing wrong…

thanks..

Edit : Bizzarre file issue is solved now the main issue is single file saving instead of multiple..
thanks again…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T12:59:24+00:00Added an answer on May 24, 2026 at 12:59 pm

    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.

    The browser doesn’t have a concept of receiving multiple files in the way you are attempting.

    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.

    Here is example code that will build a ZIP (using SharZipLib) of the images and reply with a single file called “images.zip”

    Include these using statements for SharpZipLib:

    using ICSharpCode.SharpZipLib.Core;
    using ICSharpCode.SharpZipLib.Zip;
    using ICSharpCode.SharpZipLib.Checksums;
    

    Then in the method where you want to stream back the ZIP file:

    DirectoryInfo directoryInfo = new DirectoryInfo(Server.MapPath(@"/Bailiffs/BailiffFiles/"));
    string cukurNumber = string.Empty;
    if (txtCukurNumber.Text != string.Empty) {
        cukurNumber = txtCukurNumber.Text;
    }
    
    IEnumerable<FileInfo> 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 > 0 );
            }
        }
    
        zipstream.Finish();
        zipstream.Close();
    }
    
    Response.Flush();
    Response.End();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got an example mht file here that will help demonstrate my issue; if
Ive got a VBS Script that,generates an url to download a file from a
I've got the following code to download a binary file from the web: WebClient
Hi I've got a log file containing trace routes and pings. Ive seperated these
I've got a file (possibly binary) that contains mostly non-printable ASCII characters as the
I've got a controller action that returns a FileResult like this return this.File(file.pdf, application/pdf);
I've got a very strange issue while parsing an external XAML file. The pre-history
I've got a link for a media file on the web that my application
Iv'e got an xml file containing data about games, which are an .exe download;
I've got to download, process, and store an 8GB XML file from a secure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.