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

  • Home
  • SEARCH
  • 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 8093321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:28:48+00:00 2026-06-05T20:28:48+00:00

I have a function which zips files and downloads them to the users machine.

  • 0

I have a function which zips files and downloads them to the users machine.

However, when it zips the files they are within a few folders.

For example if i want to zip a file called test.doc and it is in c:/document/the folder/test.doc

In the zipped folder there will be “document” folder and “the folder” too. I just want the document in there

here is my code…

 public FileStreamResult DownloadDocs()
    {
        MemoryStream workStream = new MemoryStream();
        ZipFile zip = new ZipFile();
        string[] fileEntries = Directory.GetFiles(Server.MapPath(SettingManager.OnlineForms));
        foreach (string fileName in fileEntries)
        {
            FileInfo fi = new FileInfo(fileName);
            string name = Server.MapPath(SettingManager.OnlineForms + fi.Name);
            zip.AddFile(name);
        }

        zip.Save(workStream);
        workStream.Position = 0;

        FileStreamResult fileResult = new FileStreamResult(workStream, System.Net.Mime.MediaTypeNames.Application.Zip);
        fileResult.FileDownloadName = "OnlineForms.zip";

        return fileResult;
    }
  • 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-06-05T20:28:49+00:00Added an answer on June 5, 2026 at 8:28 pm

    Change the line

    Zip.AddFile(name);
    

    to

    Zip.AddFile(name, string.Empty);
    

    Also you could avoid the call to get the fileinfo. The array of file names should suffice.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a function which takes a whole bunch of files, zips them
I have a function which removes all attributes in all tags except a few
I have a function which I have to loop it a few times but
I have a function which returns a referenced value by default – however, the
I have this function which removes occurrences of a given element within the list
hi i have function which is called by tinker listbox so i cannot return
I have a function which accepts a string parameter such as: var1=val1 var2=val2 var3='a
I have a function which returns a one-sided intersection of values between two input
I have foreach function which calls specified function on every element which it contains.
I have a function which performs a foreach loop on an array from a

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.