Doesn't return file in ASP.NET MVC

Aug 24, 2011 at 12:37 PM

I'm trying to return zipped file

public FileResult Download()
            MemoryStream outputStream = new MemoryStream();

            using (ZipFile zip = new ZipFile())
                zip.AddEntry("asdasd.html", "<html><body>fgdfg</body></html>");
                zip.AddEntry("asdassssd.html", "<html><body>asddsaf</body></html>");

            outputStream.Seek(0, SeekOrigin.Begin);

            return new FileStreamResult(outputStream, "application/zip") { FileDownloadName = "" };


But file there is no file..

Fiddler's RawView:

HTTP/1.1 200 OK
Server: ASP.NET Development Server/
Date: Wed, 24 Aug 2011 11:25:56 GMT
X-AspNet-Version: 4.0.30319
X-AspNetMvc-Version: 3.0
Content-Disposition: attachment;
Cache-Control: private, s-maxage=0
Content-Type: application/zip
Content-Length: 422
Connection: Close

� �����������Pb�����Pb�����Pb���(�ͱ�I�O��KKOIK���m���PK����<s?������!����$�asdassssd.html
� �������M4��Pb�M4��Pb�M4��Pb���(�ͱ�I�O��K,NI)NL���l��R�PK-�����<s?��e&������
� �����������Pb�����Pb�����Pb�PK-�����<s?������!����$�����������g���asdassssd.html
� �������M4��Pb�M4��Pb�M4��Pb�PK����������������

Help. please!

Aug 24, 2011 at 5:24 PM

I don't know ASPNET MVC so well, but it sure looks like, from Fiddler's perspective, there is a zipfile there.

It looks like it's working.


Aug 24, 2011 at 5:25 PM

What I suggest, to help diagnmose and troubleshoot, is to send a MemoryStream that you fill with other content.  Content not from a ZipOutputStream.

See if the FileStreamResult works with that content. then, when you get that sorted, add the ZipOutputStream back in.


Aug 25, 2011 at 8:51 AM

i'm sorry. The problem was that I called controller via ajax $.post

now I call it (like clicking a link):

window.location.href = '@Url.Action("Download", "Template")?templates=' + allVals


Aug 25, 2011 at 3:22 PM

and it works now? 

There's no reason why an AJAX call shouldn't also work.  On the other hand, if you're using ajax in the traditional way, then you'd be getting a zipfile into the Javascript program space in the browser, and you'd need to read the zipfile from that environment.  Which is not so simple.