Download multiple files as Zip Archive File using Grid. View in ASP. Net. In this article I will explain how to download multiple files from server on single button click by creating Zip Archive File using Dot. Net. Zip Library in ASP. Net using C# and VB. How to update data in Excel file using OLEDB In the previous examples we used Microsoft Excel 12.0 Object Library for read or write to and Excel file. How to read entire content of an excel file using C#, Reading Named Ranges in Excel using C#, How to get the range of occupied cells in excel sheet, How do I. You can with HTML5. NB: The file data returned MUST be base64 encoded because you cannot JSON encode binary data. In my AJAX response I have a data structure that. After long search search i found one jquery plugin to convert html table content into excel sheet. It is very simple to use. It supports not only table data also for. Net. Referencing the Dot. Net. Zip Library. You will need to download the Dot. Net. Zip Library DLL using the Download Link provided below. Download Dot. Net. Zip Or your will find the DLL in the attached sample at the end of the article. Once you have the DLL you need to place the Ionic. Zip. Reduced. dll in the BIN Folder. Namespaces. You will need to import the following Namespaces. C#using System. IO; using Ionic. Zip; using System. Collections. Generic; VB. In this article I will explain how to download multiple files from server on single button click by creating Zip Archive File using DotNetZip Library in ASP.Net using. Net. Imports System. IOImports Ionic. Zip. Imports System. Collections. Generic. Storage of Files on Server Directory. In my website I have created a Folder named Files which contains the following files as shown in the screenshot below. Displaying the Files stored in Folder on the Server in ASP. Net Grid. View. I have placed an ASP. Net Grid. View control on my Web Page along with a Button that will be used to download the Files. You will notice that I have placed a Check. Box Control in the Grid. View, this Check. Box will allow users to select the file that wish to download.< asp: Grid. View. ID="Grid. View. Auto. Generate. Columns="false"Empty. Data. Text="No files available"> < Columns> < asp: Template. Field> < Item. Template> < asp: Check. Box. ID="chk. Select"runat="server"/> < asp: Label. ID="lbl. File. Path"runat="server"Text='< %# Eval("Value") %> 'Visible="false"> < /asp: Label> < /Item. Template> < /asp: Template. Field> < asp: Bound. Field. Data. Field="Text"Header. Text="File Name"/> < /Columns> < /asp: Grid. View> < br/> < asp: Button. ID="btn. Download"runat="server"Text="Download"On. Click="Download. Files"/> The following code is used the bind the List of Files from the Server Folder or Directory to the ASP. Net Grid. View control. C#protectedvoid Page_Load(object sender, Event. Args e){ if (! Is. Post. Back) { string[] file. Paths = Directory. Get. Files(Server. Map. Path("~/Files/")); List< List. Item> files = new. List< List. Item> (); foreach (string file. Path in file. Paths) { files.Add(new. List. Item(Path. Get. File. Name(file.Path), file. Path)); } Grid. View. 1. Data. Source = files; Grid. View. 1. Data. Bind(); }}VB. Net. Protected. Sub Page_Load(sender As. Object, e As. Event. Args) Handles. Me. Load If. Not Is. Post. Back Then Dim file. Paths As. String() = Directory. Get. Files(Server. Map. Path("~/Files/")) Dim files As. New. List(Of. List. Item)() For. Each file. Path As. String. In file. Paths files. Add(New. List. Item(Path. Get. File. Name(file. Path), file. Path)) Next Grid. View. 1. Data. Source = files Grid. View. 1. Data. Bind() End. If. End. Sub. Downloading Multiple Files selected in Grid. View as Zip Archive File using Dot. Net. Zip. C#protectedvoid Download. Files(object sender, Event. Args e){ using (Zip. File zip = new. Zip. File()) { zip. Alternate. Encoding. Usage = Zip. Option. As. Necessary; zip. Add. Directory. By. Name("Files"); foreach (Grid. View. Row row in Grid. View. 1. Rows) { if ((row. Find. Control("chk. Select") as. Check. Box). Checked) { string file. Path = (row. Find. Control("lbl. File. Path") as. Label). Text; zip. Add. File(file. Path, "Files"); } } Response. Clear(); Response. Buffer. Output = false; string zip. Name = String. Format("Zip_{0}. Date. Time. Now. To. String("yyyy- MMM- dd- HHmmss")); Response. Content. Type = "application/zip"; Response. Add. Header("content- disposition", "attachment; filename=" + zip. Name); zip. Save(Response. Output. Stream); Response. End(); }}VB. Net. Protected. Sub Download. Files(sender As. Object, e As. Event. Args) Using zip As. New. Zip. File() zip. Alternate. Encoding. Usage = Zip. Option. As. Necessary zip. Add. Directory. By. Name("Files") For. Each row As. Grid. View. Row. In Grid. View. 1. Rows If. Try. Cast(row. Find. Control("chk. Select"), Check. Box). Checked Then Dim file. Path As. String = Try. Cast(row. Find. Control("lbl. File. Path"), Label). Text zip. Add. File(file. Path, "Files") End. If Next Response. Clear() Response. Buffer. Output = False Dim zip. Name As. String = [String]. Format("Zip_{0}. zip", Date. Time. Now. To. String("yyyy- MMM- dd- HHmmss")) Response. Content. Type = "application/zip" Response. Add. Header("content- disposition", "attachment; filename=" + zip. Name) zip. Save(Response. Output. Stream) Response.[End]() End. Using. End. Sub. Demo. How to update data in Excel file using OLEDBIn the previous examples we used Microsoft Excel 1. Object Library for read or write to and Excel file . In C# without using Excel Object we can insert , edit , delete , select etc. Excel file using OLEDB . Here we are using Ole. Db. Connection , Ole. Db. Data. Adapter , Data. Set for doing these operations in an Excel file. You have to import System. Data in the project for doing these operations . For update the content in the cell or modify the content in a cell , We can use the UPDATE command like in SQL Operations. sample UPDATE sql sql = "Update [Sheet. New Name' where id=1" The following picture shows before and after update of the Sheet.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
November 2017
Categories |