Solved

Download Form

Posted on 2013-01-24
4
244 Views
Last Modified: 2013-01-28
Hi,

I have a form which i have made a table inside of. the table has a checkbox as an input on each row of the table. each row corresponds to a document on the server. and then a submit button on the bottom of the table which reads download. i would like to create a form that allows users to select the different checkboxes and then select download and the result would be the user then downloads the items corresponding to the checkboxes. i am not sure how to accomplish this any help would be greatly appreciated

thanks jayme
0
Comment
Question by:M. Jayme Nagy
  • 2
4 Comments
 
LVL 6

Expert Comment

by:esolve
Comment Utility
Add a checkbox to a template column in your datagridview for selecting the documents for downloading.

When you click the download button you will need to iterate over the datagridrows in order to retrieve the checked listboxes. If your gridview support paging you will need to save these in a session somewhere.

Then for downloading I suggest you download all files into one zip file and stream that to the client. Theres lots of open source zip libraries availalble. We're using SharpZiplib

http://www.icsharpcode.net/opensource/sharpziplib/


//create zip file
          using (MemoryStream ms = new MemoryStream())
          {
            #region Generate the archive and add it to the MemoryStream ms

            using (ZipOutputStream zos = new ZipOutputStream(ms))
            {
             
              foreach (string sAccount in SelectedExcelItems)
              {
                //create excel
                _report = cReport.GetClientStatement(sAccount, (DateTime)rdpDate.SelectedDate);

                using (Stream stm = _report.ExportToStream(ExportFormatType.Excel))
                {
                  int iLength = Convert.ToInt32(stm.Length);
                  byte[] bData = new byte[iLength];
                  stm.Read(bData, 0, iLength);

                  ZipEntry oZipEntry = new ZipEntry(sAccount + ".xls"); //filename
                  zos.PutNextEntry(oZipEntry);
                  zos.Write(bData, 0, iLength);
                  zos.CloseEntry();

                  stm.Close();
                }
              }

              // Finish is important to ensure trailing information for a Zip file is appended.  Without this
              // the created file would be invalid.
              zos.Finish();
            }

            #endregion

            // Send the file to the client
            Response.ContentType = "application/zip";
            Response.AppendHeader("Content-Disposition", "attachment; filename=ArchivedFiles.zip");
            Response.AppendHeader("Content-Description", "ArchivedFiles.zip");

            Response.Clear();
            Response.Buffer = true;
            Response.BinaryWrite(ms.ToArray());
            Response.Flush();
            Response.End();
          }



The SelectedExcelItems is just a property which contains a string collection of selected eg.ClientAccounts in my case. In my case I will download a statement for each client account.

The _report I have used is a Crystal Decisions ReportDocument which I stream into a byte array. Depending on how you save your document you only need to get this into a byte array.

Hope it helps
0
 
LVL 10

Expert Comment

by:John Claes
Comment Utility
If you would let the user select the files and then you send it to him (after pressing a donwload button)


i would suggest to return a Zipfile.
this way, you loop through the selected files, adding it to a zip file in memory and then you can send it to the user.
there are a lot of zipping references to be used
0
 
LVL 6

Author Comment

by:M. Jayme Nagy
Comment Utility
esolve WOW!

i think this may be a little bit over my head but here is what i can grasp a little more clarification will go a long way with me as im fairly new.

Firstly, i will explain a little more of what im working with. i have a linux server hosted on godaddy with about 20 files one it of varying sizes and formats. i have placed restrictions/premissions via CHmod on the folder than contains these files on the server. i have then created a seperate .php that lists all these documents within a table. the table has one row for each document on the server and six columns. the columns from left to right include:
 1. checkboxes
 2.  Names of document
 3. document identifier
 4. description of document
 5. version of document
 6. upload date

to accomplish the checkbox functions i have placed the entire table within a form. i have not given the form a name or action its simply <form>

i have then gone down on the first column to give a checkbox with a unique name and id to each row/document
<input type="checkbox" name="checkbox-1" id="checkbox-1"/>

at the very bottom i have included two buttons.

Once for select all and the other for unselect <-- havent got those to work yet but i just thought of the idea this morning.

finally, i have put a third input as a submit with the name, value, id oF Download and closed the form

this is pretty much where i am at the moment. i like your idea about placing it into a zip file i think that is a great idea. however i am not sure how i would go about this.

any help will be greatly appreciated

thanks!!!
0
 
LVL 6

Accepted Solution

by:
esolve earned 500 total points
Comment Utility
Sorry my code is in ASP.NET. I did not realise you're working with PHP. You should be able to do the same thing in PHP.

You can easily achieve your select/unselect all which I think is a proper way to do this. You will have to get a open source zip library for PHP which there should be a lot. Then similar to my code you should iterate over the rows and save the selected checkboxes in an array (php or jscript).

Maybe theres some experts that have done this in php. If I have more time i'll try do get some php examples for you.

Good luck
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now