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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:26:51+00:00 2026-05-26T05:26:51+00:00

I have a simple feedback form that allows my users to log feedback and

  • 0

I have a simple feedback form that allows my users to log feedback and optionally upload files related to the problem. The files can be of any format, not just images.

The server side code on the controller looks like this:

    [HttpPost]
    public ActionResult Create(Entry entry)
    {
        try
        {
            foreach (string inputTagName in Request.Files)
            {
                HttpPostedFileBase file = Request.Files[inputTagName];

                if (file != null && file.ContentLength > 0)
                {
                    using (MemoryStream ms = new MemoryStream())
                    {
                        file.InputStream.CopyTo(ms);

                        db.Files.Add(new Models.File
                        {
                            Entry = entry,
                            FileName = Path.GetFileName(file.FileName),
                            FileContents = ms.GetBuffer()
                        });
                    }
                }
            }

            entry.Status = Status.Open;
            entry.Severity = Severity.Medium;
            entry.DateSubmitted = DateTime.Now;

            db.Entries.Add(entry);
            db.SaveChanges();

            return View("Complete");
        }
        catch
        {
            return View("Error");
        }
    }

I also have a controller action that lets me download the entire database into a zip and send it to my browser:

    public ActionResult Download()
    {
        MemoryStream fileStream = new MemoryStream();
        StringBuilder csv = new StringBuilder();
        csv.AppendLine("Id,Summary,Description,Company,Name,Email,Telephone,Version,Area,Date Submitted,Notes,Resolution,Date Resolved");

        using (ZipFile zip = new ZipFile())
        {
            foreach (Entry entry in db.Entries.ToList())
            {
                csv.AppendFormat("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12}",
                                 entry.Id,
                                 entry.Summary,
                                 entry.Description,
                                 entry.Company.Name,
                                 entry.Name,
                                 entry.Email,
                                 entry.Telephone,
                                 entry.Version.Number,
                                 entry.Area,
                                 entry.DateSubmitted,
                                 entry.Notes,
                                 entry.Resolution,
                                 entry.DateResolved);

                if (entry.Files.Count > 0)
                {
                    foreach (FeedbackManager.Models.File file in entry.Files)
                    {
                        using (MemoryStream ms = new MemoryStream())
                        {
                            ms.Write(file.FileContents, 0, file.FileContents.Length);
                            ms.Flush();
                            zip.AddEntry(entry.Id+"_"+file.FileName, ms.GetBuffer());
                        }
                    }
                }
            }

            zip.AddEntry("feedback.csv", csv.ToString());

            zip.Save(fileStream);
        }

        return File(fileStream.GetBuffer(), "application/zip", String.Format("FeedbackToDate_{0}.zip", DateTime.Now.Date.ToShortDateString()));
    }

The problem im having is reading the file data back out of the database, the zip file is getting corrupted some how and im not able to open it, if I exclude the files, I can open the zip file and I can read the csv fine.

Whats the correct way of pulling these files back out of the DB, do I need to save to the file system first? Is the file data getting corrupted some how? How do I perserve the raw binary data so the content is unaffected?

Thanks

  • 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-26T05:26:52+00:00Added an answer on May 26, 2026 at 5:26 am

    Use MemoryStream.ToArray() instead of MemoryStream.GetBuffer() -> http://msdn.microsoft.com/en-us/library/system.io.memorystream.toarray.aspx

    MemoryStream.GetBuffer() might also return unused bytes which are not part of the content.

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

Sidebar

Related Questions

Hello I have a simple form on my site that allows users to send
I have a simple feedback form PHP script that I would like to enhance
I have simple WinForms application where modifying Windows Registry. The problem is that in
I have a simple jsp form that the customer uses to send us emails.
I have a simple swf file upload script that uploads a file as soon
I have a pretty complex form that provides real-time validation and feedback to the
I have simple win service, that executes few tasks periodically. How should I pass
I have simple form. <form target=_blank action=somescript.php method=Post id=simpleForm> <input type=hidden name=url value=http://...> <input
I am aware that I can Google HTML Form Validation and would get a
I'm submitting a form, sometimes I have some messages that I want to show

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.