Extract Files From Zip Files and Delete the Zip Files once UnZiped in SSIS Package - SQL Server Integration Services(SSIS) Tutorial

Scenario:

On daily basis we get zip files those can contain single file or more than one files of different types. We want to create an SSIS Package that can loop through all zip files and extract the files from them and save them to a folder from where we can load them to different destinations in SSIS Package.

Solution:

In this video we will learn the solution of our given scenario and create an SSIS Package. Below is the list of items we will cover in this video


  1. How to Loop through zip files in SSIS Package
  2. How to create Package Parameters for Zip and UnZip folders and use them in Script Task
  3. How to Change Dot Net Framework from 4 to 4.5 in Script Task
  4. How to add Assemblies such as System.IO.Compression and System.IO.Compression.FileSystem in Script Task
  5. How to Extract Files from Zip file to folder and then delete the zip file in SSIS Package by using Script Task

Script used in the video to Unzip the Zip files 

 public void Main()
        {

            string zipfullpath = Dts.Variables["User::ZipFullPath"].Value.ToString();
            string inputfolder = Dts.Variables["$Package::InputFolder"].Value.ToString();

         using (ZipArchive arch= ZipFile.OpenRead(zipfullpath))
            {
                foreach(ZipArchiveEntry entry in arch.Entries)
                {
                    entry.ExtractToFile(Path.Combine(inputfolder,entry.FullName));
                }
            }
            File.Delete(zipfullpath);
            // TODO: Add your code here

            Dts.TaskResult = (int)ScriptResults.Success;
        }




3 comments:

  1. Getting dts error: DTS Script Task has encounter an exception in user code

    ReplyDelete
  2. Exception has been thrown by the target of an invocation.

    ReplyDelete
  3. Amazing, this is great as you want to learn more, I invite to This is my page. Satta result

    ReplyDelete