Making Zip filer with Azure

Jul 18, 2010 at 2:00 PM

I have some asp.net code which plops a number of files into a zip file for download. It does not compression - it's just to ensure one download.

I've migrated this to Azure and it no longer works.  The particular issue is a 'Not Supported Exception' which offurs On HttpResponseStream.Position.get() (called from CountingStream constructor called freom ZipFile.Save).

Of course the original code was reading from files and this version is now reading from CloudBlob streams.

The code looks like below.  My original code was against v1.7, but I have downloaded v1.9 (and changed a couple of lines).

Be grateful for any suggestions

Iain

List<ItemInfo> items = GetForOrder(OrderID);
ZipFile zipper = new ZipFile();
zipper.CompressionLevel = Ionic.Zlib.CompressionLevel.Level0;
List<Stream> Streams = new List<Stream>();
try
{
    foreach (ItemInfo item in items)
    {
        CloudBlob blob = PBLiteFileUpDownload.GetBlob(item.PriceCode, MediaType, item.ContentID);
        try
        {
            blob.FetchAttributes();
        }
        catch
        {
            throw new InvalidOperationException(string.Format("No content {0}.{1}", item.ContentID, MediaType));
        }
        if (blob.Properties.Length == 0)
            throw new InvalidOperationException(string.Format("No content {0}.{1}", item.ContentID, MediaType));

        string cleanName = FileNameAsTitleArtist(item.Title, item.Artist, MediaType);
        Stream stream = blob.OpenRead();
        Streams.Add(stream);
        zipper.AddEntry(cleanName, stream); //.AddFileStream(cleanName, "", stream);
    }
    Response.Clear();
    Response.AppendHeader("Content-Disposition", string.Format("attachment; filename={0}_{1}.zip",
        OrderID, MediaType));
    Response.ContentType = "application/x-zip-compressed";
    Response.Buffer = false;
    zipper.Save(Response.OutputStream);   //<< Not Supported eXCEPTION
    Response.Flush();
    Response.End();
}

Jul 26, 2010 at 9:19 AM

OK.  It seems I'm not paying attention.

The exception is raised and it is ignored / handled within DotNetZip.  However, if you are running under the debugger, NotSupportedException defaults to break on thrown which in turn 'threw' me (ha ha).

So there is no issue here.  It would be nice though if this condition was handled without using exceptions...

 

Iain