Scenario:
We get text files in our Input Folder and we need to run our SSIS Package multiple times a day and load those files to table/s and then zip those files in a file with datetime in Archive Folder.Solution:
We will be using .NET Framework 4.5 and ZipFile class to handle this scenario by using in Script Task in SSIS Package.
Here are the items you will learn in this video
- How to read multiple Text files with same metadata and load to SQL Server Table, we will make use of Foreach Loop Container to loop through files
- How to Create Package Parameters in SSIS Package for Input Folder and Archive folder path
- How to use Package Parameters in Script Task
- How to change .NET Framework in Script task from 4 to 4.5 so we can use ZipFile Class
- How to Add reference to Assembly System.IO.Compression.FileSystem
- How to Zip the Files to folder with Datetime and then delete them from input Folder in Script Task
Script used in the Script task to Zip the files to Zip File with Datetime and delete from Input Folder
public void Main() { //set the value to local variables string inputfolder=Dts.Variables["$Package::InputFolder"].Value.ToString(); string archpath = Dts.Variables["$Package::ArchFolder"].Value.ToString() +
"Sales_" + DateTime.Now.ToString("yyyyMMddHHmmss")+".zip"; //Create Zip File with Datetime and put all the files from input folder ZipFile.CreateFromDirectory(inputfolder, archpath); //Delete all the files from Input Folder DirectoryInfo Dir = new DirectoryInfo(inputfolder); foreach (FileInfo File in Dir.GetFiles()) { File.Delete(); } // TODO: Add your code here Dts.TaskResult = (int)ScriptResults.Success; }
How to load multiple files in SSIS Package and Zip(Compress) them after loading in SSIS Package
Related Posts/Videos on Zip / UnZip by Script Task
- How to change .NET Framework version in Script Task and Add Reference to Assembly(ZipFile Demo)
- Extract Files From Zip Files and Delete the Zip Files once Unzipped in SSIS Package
- Load File/s, Zip and Delete from Source Folder in SSIS Package
- Zip ( Compress) Files and Add them to Folder According to Extension in SSIS Package
- Zip or Compress Files according to the Name of Files in SSIS Package
- Get File names from Zip Files and Insert into SQL Server Table in SSIS Package
- How to Zip ( Compress) Multiple Folders and Delete in SSIS Package
- Create Zip file per day with Date Only and Add Files to it in SSIS Package
Where can i download the input files?
ReplyDelete