web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Adding files entries to zipfiles in ax 2012

(0) ShareShare
ReportReport
Posted on by 47

HI All,

I am trying to use System.IO.Compression class and I want to add pdf files to the existing zip file without using Ionic.Zip.ZipFile dll.

System.IO.Compression.ZipFileExtensions::CreateEntryFromFile() method needs ZipArchive as a parameter but does AX 2012 support Zip Archive?

I know D365 / dotnet 4.5 has support for System.IO.Compression.ZipArchive but AX 2012 does not. I want to know how can I

use System.IO.Compression.ZipFileExtensions::CreateEntryFromFile() in AX 2012?

Thanks,

Vaishnavi

I have the same question (0)
  • André Arnaud de Calavon Profile Picture
    301,119 Super User 2025 Season 2 on at

    Hi Vaishnavi,

    The platform for Dynamics 365 is different and has other options. You can check which dll is used in Dynamics 365 and see if you can add this one as resource to be used in AX2012.

    Why do you not want to use Ionic.Zip.Zipfile? Is it missing some features?

  • Suggested answer
    Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    What if you try to add such a reference to System.IO.Compression libraries?

    What's the exact version of your AX? Different updates support different versions of .NET framework.

    If it can't be done directly in AX, you can develop a separate .NET 4.5+ application and let it communicate with AX 2012.

  • Vaishnavi Profile Picture
    47 on at

    Thank you Martin, Andre,

    I was able to add System.IO.Compression  v 4.5 libraries, I am able to use the extended features now.

    How ever, When I create a zip file using System.IO.Compression.ZipFileExtensions::CreateEntryFromFile(), the zip file gets created but when I try to use it/extract or view in the windows folder, I get an error message that zip file is empty, cannot be extracted. whereas the zip file, in reality, shows the memory size in properties which means it is not empty. 

    I had to use the memory stream and file stream classes to copy the file, which now works.

    Thanks,

    Vaishnavi G.

  • nmaenpaa Profile Picture
    101,162 Moderator on at

    Perhaps the problem is not in the zip file but your Windows?

    Could you try to install some standalone zip management program such as 7zip and see if you can then unzip the package?

  • Vaishnavi Profile Picture
    47 on at

    Hi Nikolaos Mäenpää,

    I did try using different zip extractors. I think the file that is being created using that function has issues. When I use file stream classes and add files to zip, it works fine.

    Or maybe I am not using the function properly.

    Here is example of what I used:

       str zipPath = @"C:\Users\vgubba\start.zip";

       str newFile = @"c:\users\vgubba\TEST.pdf";

    archive=System.IO.Compression.ZipFile::Open(zipPath, System.IO.Compression.ZipArchiveMode::Create);

                  System.IO.Compression.ZipFileExtensions::CreateEntryFromFile(archive,newFile, "TEST1.pdf");

    archive.Dispose();

    However the below code works:

    zipArchive = System.IO.Compression.ZipFile::Open(zipPath, System.IO. Compression.ZipArchiveMode::Create);

       fileEntry              = zipArchive.CreateEntry("TEST1.pdf");

       fileEntryStream   = fileEntry.Open();

       fileStream      = System.IO.File::Open(newFile,System.IO.FileMode::Open);

       fileStream.CopyTo(fileEntryStream);

       fileStream.Close();

       fileEntryStream.Close();

       zipArchive.Dispose();

    Thanks,

    Vaishnavi.

  • Verified answer
    Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    Maybe your code failed and you didn't notice it. Try this:

    str zipPath = @"C:\Users\vgubba\start.zip";
    str newFile = @"c:\users\vgubba\TEST.pdf";
    
    try
    {
    	archive = System.IO.Compression.ZipFile::Open(zipPath, System.IO.Compression.ZipArchiveMode::Create);
    	System.IO.Compression.ZipFileExtensions::CreateEntryFromFile(archive, newFile, "TEST1.pdf");
    	archive.Dispose();
    }
    catch (Exception::CLRError)
    {
    	throw error(AifUtil::getClrErrorMessage());
    }

  • Vaishnavi Profile Picture
    47 on at

    Hi Martin,

    Thank you very much.

    When I added the try catch as you suggested, I did not get any error, Instead I got the proper zipfile that works( I can open the zip file now).

    that helped.

    Thanks,

    vaishnavi G.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 451 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 428 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans