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 8059469
In Process

The Archive Base Latest Questions

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

I use C#-MVC3. I have an export page. I have some functions for exporting

  • 0

I use C#-MVC3. I have an “export” page. I have some functions for exporting different tables from the DB, every function creates a CSV file from the table and returns a FileContentResult file to the user.

Now I want to create a button for “export all”, to download all the files at once.
I tried to use ZipFile but it gets only file names and path – files that were saved on the server, not “FileContentResult” files.

So I wanted to save the “FileContentResult” files temporarily on the server, zip them and delete them – but I can’t find how to save a “FileContentResult” file.

If you can help me or give me another idea, I’ll glad to hear.

  • 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-05T09:40:50+00:00Added an answer on June 5, 2026 at 9:40 am

    my solution:

        public ZipFile DownloadAllToZip()
        {
            string path = "c:\\TempCSV";
            try
            {
                if (Directory.Exists(path))
                {
                    EmptyFolder(path);
                }
                else
                {
                    DirectoryInfo di = Directory.CreateDirectory(path);
                }
                List<FileContentResult> filesToExport = GetAllCSVs();
    
                foreach (var file in filesToExport)
                {
                    try
                    {
                        using (FileStream stream = new FileStream(path + "\\" + file.FileDownloadName, FileMode.CreateNew))
                        {
                            using (StreamWriter writer = new StreamWriter(stream, Encoding.UTF8))
                            {
                                byte[] buffer = file.FileContents;
                                stream.Write(buffer, 0, buffer.Length);
                                writer.Close();
                            }
                        }
                    }
                    catch { }
                }
            }
            catch{ }
    
            Response.Clear();
            Response.BufferOutput = false;
            Response.ContentType = "application/zip";
            Response.AddHeader("content-disposition", "attachment; filename=MaterialAssetTracker.zip");
            ZipFile zip= new ZipFile();
            using (zip)
            {
                zip.CompressionLevel = CompressionLevel.None;
                zip.AddSelectedFiles("*.csv", path + "\\", "", false);
                zip.Save(Response.OutputStream);
            }
            Response.Close();
            EmptyFolder(path);
            return zip;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

MVC3, VB.NET. I have a function in my app that is supposed to use
I am new to MVC3.0 and have to use jquery. I as wondering some
In my MVC3 application I have many different screens and these all use a
I have an MVC3 application, I know that for relative paths, I can use
If I have an MVC3 ASP.net page which contains a the model iEnumerable<mymodel.CarsForHire> -
I have an MVC3 project for which I use NinjectMVC3 for dependency injection -
I have a MVC3 application, based on default layout from VS 2010, which I
I am quite new on mvc3 and have some basic and ridiculous questions that
I have a MVC3 Web Application project that I develop and publish from Visual
I am building an asp.net mvc3 application and I have decided to use areas

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.