2

Is it possible to create a zip file using Sitecore FileUtil.ZipFiles where the files to be added are from the Media Library items?

1 Answer 1

3

No, it's not possible wit FileUtil only.

What you can do is:

  1. Add a reference to Sitecore.Zip.dll
  2. Use Sitecore.Zip.ZipWriter class like that:
using (ZipWriter zw = new ZipWriter(FileUtil.MapPath("/test.zip")))
{
    var mediaItem = new MediaItem(item);
    zw.AddEntry(mediaItem.Name + "." + mediaItem.Extension, mediaItem.GetMediaStream());
}

Remember that your IIS process user must have write access to the folder where you want to create the zip file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.