Zip a folder using SSIS

偶尔善良 提交于 2019-12-02 06:16:27

Adding a Script Task, yuo can use the ZipFile (class) here reference, you must refer to the System.IO.Compression.FileSystem assembly in the project (.NET Framework 4.5).

You need to provide to the Script Task the folder to be zipped and the name of the compressed folder as ReadOnlyVariables (to be added in the tab ReadOnlyVariables)

These two variables must be defined in the Variables tab (String type) of the package and can be changed dynamically through a cycle (eg. for each)

I use these two variables:

sFolderCompressed - the folder '.zip' that you want to obtain eg. C:\folder1\result.zip 
sFolderSource - the source folder containing the files affected eg. C:\folder1\folder2

The script is made using c#, choose Script Language: Microsoft Visual C#

This is the code to be added in the Main method:

using System.IO.Compression;

    public void Main()
    {
        try
        {
            string zipPath = (string)Dts.Variables["User::sFolderCompressed"].Value;
            string startPath = (string)Dts.Variables["User::sFolderSource"].Value;


            ZipFile.CreateFromDirectory(startPath, zipPath);
        }
        catch (Exception objException)
        {
            Dts.TaskResult = (int)ScriptResults.Failure;
            // Log the exception
        }
        Dts.TaskResult = (int)ScriptResults.Success;
    }

I hope can help.

Try using 7zip it is free. Take a look at 7zip command line user guide it contains all commands you need

And use a script task or an execute process task to achieve this. Also there are other useful links:

UPDATE 1

you can follow this link for winzip:

In the link above they suggested using this command:

 wzzip "c:\Test.zip" "c:\myfolder" -exPR

Write these things in bat file... "C:\Program Files\WinZip\WINZIP64.EXE" -a "C:\Desktop\destination_folder\Sample.zip" "C:\Desktop\Sample"

In Execute process task:

Mention the location of bat file in Execute process Task-->Process-->Executable.

It's work fine.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!