Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I'm working on a solution to combine a few files into a .zip and return it to the browser.
I'm looking to use the included zip-library ICSharpCode.SharpZipLib.Zip;
Any chance someone has an example of this? What kind of result should my action return?
There are a few bits an pieces to consider, but basically you need to return the File, however there are a couple of different ways of doing this.
You can return a FilePathResult, as demonstrated here: https://www.c-sharpcorner.com/UploadFile/db2972/file-result-in-controller-sample-in-mvc-day-15/
You can also return a FileStreamResult discussed in the question here:
Or you can roll your own HttpResponseMessage as demonstrated here:
There is also a FileContentResult which I couldn't find an example of quickly (sorry)
Each approach has different benefits and I think in the past I've generally used a FileContentResult to return files from controllers.
Thanx for your input, Nik!
I ended up using a FileContentResult like this;
return (ActionResult)this.File(this.GetFile(this.Server.MapPath("/zip/" + (object)productPageID + "datasheets.zip")), "application/octet-stream", "datasheets.zip");
the GetFile method returns a byte-array like this;
private byte GetFile(string s)
FileStream fileStream = System.IO.File.OpenRead(s);
byte buffer = new byte[fileStream.Length];
if ((long)fileStream.Read(buffer, 0, buffer.Length) != fileStream.Length)
throw new IOException(s);
This works like a charm :)
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted