using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; namespace ZipTnterop { public class ZipInterop : System.Web.UI.Page { protected System.Web.UI.WebControls.TextBox txtUrl; protected System.Web.UI.WebControls.Button cmdZip; protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1; protected System.Web.UI.WebControls.Label lblDisplay; protected DartZip.Zip Zip1 = new DartZip.ZipClass(); protected DartZip.DartStream stream1 = new DartZip.DartStreamClass(); protected System.Web.UI.WebControls.Button cmdGetFile; protected System.Web.UI.WebControls.Button cmdTryAgain; protected System.Web.UI.WebControls.Label lblUrl; protected System.Web.UI.WebControls.Label Label1; protected System.Web.UI.WebControls.Label Label2; protected DartZip.SpanSettings span1 = new DartZip.SpanSettingsClass(); private void Page_Load(object sender, System.EventArgs e) { // Put user code to initialize the page here if(!Page.IsPostBack) { Label1.Text = "
PowerTCP Zip Compression Tool Product Interop Example
This example demonstrates how the PowerTCP Zip Compression Tool is integrated with the rest of the PowerTCP product line through DartStream technology.
In this example, The WebASP Control is used to grab any file on the Internet. The body of the response from the server is a DartStream. We simply use the FileStore.Add method to add the DartStream then zip. The compressed file is returned as the response to the browser.
Try It! Enter the url of any file on the Internet. For best results, choose a file greater than 1K (to see a worthwhile size reduction) and less than 1 MB (so HTTP retrieval doesn't take too long). Also, be sure to enter the URL of a file that is highly compressable (choose .htm, .asp, .bmp, or .doc files over .jpg, .gif, or .wav files).
"; } } #region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); } ///Error
"; lblDisplay.Text = "Error. Status code " + WebASP1.Response.Status + " received while attempting to retrieve the file at the url " + txtUrl.Text + ". Please try again."; pageRetrieved = false; } } catch { Label2.Visible = true; Label1.Visible = false; Label2.Text = "Error
"; lblDisplay.Text = "Error. Unable to retrieve the file at the url: " + txtUrl.Text + ". Please try again."; } if(pageRetrieved) { // create new stream and write bytes of response to it DartZip.DartStream streamTemp = new DartZip.DartStreamClass(); WebASP1.Response.Body.Position = 0; streamTemp.Write(WebASP1.Response.Body.ReadBytes(0),0); // add new stream to filestore Zip1.FileStore.Add(streamTemp , false, false, "", DartZip.EncryptionConstants.zipNoEncryption); // set the filename in the zip string outFile = txtUrl.Text.ToLower().Replace("http://","").Replace("https://","").Replace("/","\\"); Zip1.FileStore.Item(1).Name = new System.IO.FileInfo(outFile).Name; sizeBefore = Zip1.FileStore.Item(1).Size; try { Zip1.FileStore.Zip(stream1, span1); stream1.Position = 0; sizeAfter = stream1.Size; Label2.Visible = true; Label1.Visible = false; Label2.Text = "The file has been successfully zipped. Click the button below to receive your zipped file." + "
"; lblDisplay.Text += "| Zip Statistics | |
| File Size Before Zipping | " + sizeBefore + " |
| File Size After Zipping | " + sizeAfter + " |
| Percent Reduction of File Size | This file wasn't compressed very much. Are you sure you chose a compressible file? Some file types (.jpg, .gif, .wav, for example) are already highly compressed and as a result, the amount of additional compression that can be achieved is little to none. Be sure to choose a compressible file such as any ascii file or nonascii files such as .bmp and .doc files. |
| Percent Reduction of File Size | " + percentReduction.ToString("0.00") + " |