web
You’re offline. This is a read only version of the page.
close
Skip to main content
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)
  • Vaishnavi Profile Picture
    47 on at
    RE: Adding files entries to zipfiles in ax 2012

    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.

  • Verified answer
    Martin Dráb Profile Picture
    235,876 Most Valuable Professional on at
    RE: Adding files entries to zipfiles in ax 2012

    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
    RE: Adding files entries to zipfiles in ax 2012

    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.

  • nmaenpaa Profile Picture
    101,160 Moderator on at
    RE: Adding files entries to zipfiles in ax 2012

    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
    RE: Adding files entries to zipfiles in ax 2012

    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.

  • Suggested answer
    Martin Dráb Profile Picture
    235,876 Most Valuable Professional on at
    RE: Adding files entries to zipfiles in ax 2012

    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.

  • André Arnaud de Calavon Profile Picture
    297,316 Super User 2025 Season 2 on at
    RE: Adding files entries to zipfiles in ax 2012

    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?

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…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

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

#1
Sohaib Cheema Profile Picture

Sohaib Cheema 745 User Group Leader

#2
Martin Dráb Profile Picture

Martin Dráb 597 Most Valuable Professional

#3
André Arnaud de Calavon Profile Picture

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

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans