Using (System.IO.Stream entryStream = zipItem.Open()) System.IO.Compression.ZipArchiveEntry zipItem = zip.CreateEntry(image.Name + "." + extension) If (String.IsNullOrEmpty(extension)) continue Var media = MediaManager.GetMedia(mediaItem) Using (System.IO.Compression.ZipArchive zip = new System.IO.Compression.ZipArchive(zipStream, System.IO., true)) using (System.IO.MemoryStream zipStream = new System.IO.MemoryStream()) There are NuGet packages that can do this for you, but it can actually be accomplished without installing any extra libraries. However, it is only possible to send one file in a response, so if you want to download multiple files at once, you have to aggregate multiple memory streams into a single zip file. ![]() To download an image from the server, you take the Stream of the image file and write it to the response as a ByteArray. ![]() You can copy the contents of the file on a server, or you can dynamically generate a file as a string and send it in the Response formatted as txt, csv, etc. Downloading a single file from a server to the user’s machine is pretty easy: you open the file, write it to the HttpContext Response, and flush the Response.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |