Scenario:
We have a lot of folders in one of our Source Folder, we want to zip all of them to Archive folder. Each Folder will be zipped to its own file. Once the folders are zipped we want to delete them from Source Folder.Solution:
To perform this requirement, we will be using Script task. Here are the things that you will learn in this video.
- How to create SSIS Package Parameters for SourceFolder and ArchFolder paths
- How to Map the Package Parameters to Script Task in SSIS Package
- How to change .NET Framework from 4. to 4.5 version in Script Task in SSIS Package
- How to Add reference to assemblies such as System.IO.Compression and System.IO.Compression.FileSystem
- Loop through folder names one by one by using Foreach Loop inside Script Task and Zip them and delete them.
Script used in the Script task to Zip Multiple Folders in SSIS Package
public void Main() { //Assign values to local variable from Package Parameters string inputfolder = Dts.Variables["$Package::SourceFolder"].Value.ToString(); string archfolder = Dts.Variables["$Package::ArchFolder"].Value.ToString(); //Loop through folders and zip them and delete them from Source folder foreach (string dir in Directory.GetDirectories(inputfolder)) { //MessageBox.Show(s); //get only folder name form full path string foldername = dir.Replace(inputfolder, ""); //Zip the input folder to file ZipFile.CreateFromDirectory(dir, archfolder+foldername+".zip"); //Delete the folder Directory.Delete(dir,true); } Dts.TaskResult = (int)ScriptResults.Success; }
Zip Multiple Folders to Separate Zip Files and then Delete from Source Directory in SSIS Package
can it be done using .net framework 4.0, if so , then could we get a video on that?
ReplyDeletenice post.
ReplyDeletemsbi online training
osb training