using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using ICSharpCode.SharpZipLib.Zip; namespace Triggerless.Zip { public partial class Chkn1 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { int productID; if (!int.TryParse(Request["productID"], out productID)) { Response.ContentType = "text/plain"; Response.Write("Invalid Product ID in query string"); return; } Response.ContentType = "application/octet-stream"; Response.AddHeader("Content-Disposition", "attachment; filename=derived_" + productID + ".chkn"); byte[] buffer = new ChknCreator().Create(productID); Response.BinaryWrite(buffer); } } public class ChknCreator { public byte[] Create(int productID) { MemoryStream stream = new MemoryStream(); ZipOutputStream zoStream = new ZipOutputStream(stream); zoStream.SetLevel(5); ZipEntry jsonEntry = new ZipEntry("imvu-internal.json"); jsonEntry.DateTime = DateTime.Now; zoStream.PutNextEntry(jsonEntry); byte[] jsonBytes = Encoding.ASCII.GetBytes("{}"); zoStream.Write(jsonBytes, 0, jsonBytes.Length); ZipEntry indexEntry = new ZipEntry("index.xml"); indexEntry.DateTime = DateTime.Now; zoStream.PutNextEntry(indexEntry); const string TEMPLATE = "\n\n"; byte[] indexBytes = Encoding.UTF8.GetBytes(string.Format(TEMPLATE, productID)); zoStream.Write(indexBytes, 0, indexBytes.Length); zoStream.Finish(); stream.Position = 0; byte[] result = new byte[stream.Length]; stream.Read(result, 0, result.Length); return result; } } }