Create Zip File with Date and Keep adding files to it after loading for the same day in SSIS Package - SQL Server Integration Services(SSIS) Package

Scenario:

We get multiple files during a day and night. we have scheduled to run our SSIS Package every hour. We want to create a Zip file per day and then keep adding the files to it after loading in the same day. Next day a new Zip file should be automatically created and files should be copied to that after loading.


Solution:

In this video we will learn the solution for our scenario " How to Create A Zip File with Date Per day and add files to it after loading in SSIS Package". Below are the list of items we will learn in this video


  1. How to Create Package Parameters for InputFolder and ArchFolder so we can change the values of them according to the environment ( QA, UAT, Prod) and we don't have to make any changes in the SSIS Package. 
  2. How to use Foreach Loop Container to look through files in SSIS Package
  3. Save File name in FileName Variable From Foreacah Loop Container
  4. How to Change .NET Framework 4 to 4.5
  5. How to add reference to Assemblies such as System.IO.Compression and System.IO.Compression.FileSystem
  6. Create empty Zip File by using Script Task
  7. Add file to Zip file by using Script task in SSIS Package


Script used in Script Task to Create Zip file with Date and Add Files to Zip File in SSIS Package


public void Main()
        {


            //Assign values to local variable from SSIS Package Parameters and Variables
            string zipfile = Dts.Variables["User::ArchFullPath"].Value.ToString();
            string ArchFolder = Dts.Variables["$Package::ArchFolder"].Value.ToString();
            string filename = Dts.Variables["User::FileName"].Value.ToString();
            string inputfilepath = Dts.Variables["$Package::InputFolder"].Value.ToString() + filename;


            //If zip File already exist for the same day, just add the files to it
            if (
            File.Exists(zipfile))
            {
                MessageBox.Show(" Zip File does Exists");
                using (ZipArchive addfile = ZipFile.Open(zipfile, ZipArchiveMode.Update))
                {
                    addfile.CreateEntryFromFile(inputfilepath, filename);
                    File.Delete(inputfilepath);
                }

                //If zip file does not exist for the day, create it and add files to it
            }
            else
            {
                MessageBox.Show("File Does not exists");
                var fileStream = new FileStream(zipfile, FileMode.Create);
                fileStream.Close();

                using (ZipArchive addfile = ZipFile.Open(zipfile, ZipArchiveMode.Update))
                {
                    addfile.CreateEntryFromFile(inputfilepath, filename);
                    File.Delete(inputfilepath);
                }

            }


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

Expressions for ArchFullPath Variable:
@[$Package::ArchFolder]+Replace(Substring((DT_WSTR,30)GEtdate(),1,10),"-","_")+".zip"






30 comments:

  1. Hi Sir,

    Could you please create a post which will convert csv file to password protected using ssis

    Regards,
    Anmol

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. Now I know that I was reading a blog with a post that is very commete. Thank you for sharing the information you post. I just subscribe to your blog. This is a great blog.adding therapists

    ReplyDelete
  4. Normally, presumed file transfer specialist co-ops acknowledge installment through Visa or Paypal.transfer files

    ReplyDelete
  5. I know this is one of the most meaningful information for me. And I'm animated reading your article. But should remark on some general things, the website style is perfect; the articles are great. Thanks for the ton of tangible and attainable help. convert pdf to png

    ReplyDelete
  6. This particular is usually apparently essential and moreover outstanding truth along with for sure fair-minded and moreover admittedly useful My business is looking to find in advance designed for this specific useful stuffs… video upload

    ReplyDelete
  7. This method saved me so much time. convert pdf to png is able to search a large document after following these steps. Thank you!!

    ReplyDelete
  8. Nice to be visiting your blog once more, it has been months for me. Well this article that ive been waited for therefore long. i want this article to finish my assignment within the faculty, and it has same topic together with your article. Thanks, nice share. 먹튀사이트

    ReplyDelete
  9. Cool stuff you have got and you keep update all of us. 메이저사이트

    ReplyDelete
  10. Someone Sometimes with visits your blog regularly and recommended it in my experience to read as well. The way of writing is excellent and also the content is top-notch. Thanks for that insight you provide the readers! 카지노사이트검증

    ReplyDelete
  11. I really like your writing style, great information, thankyou for posting. 먹튀검증

    ReplyDelete
  12. Good website! I truly love how it is easy on my eyes it is. I am wondering how I might be notified whenever a new post has been made. I have subscribed to your RSS which may do the trick? Have a great day! 먹튀검증

    ReplyDelete
  13. I got too much interesting stuff on your blog. I guess I am not the only one having all the enjoyment here! Keep up the good work. website

    ReplyDelete
  14. i am always looking for some free stuffs over the internet. there are also some companies which gives free samples. 안전놀이터

    ReplyDelete
  15. Thankyou for this wondrous post, I am glad I observed this website on yahoo. 토토사이트

    ReplyDelete
  16. We are really grateful for your blog post. You will find a lot of approaches after visiting your post. I was exactly searching for. Thanks for such post and please keep it up. Great work. 릴게임

    ReplyDelete
  17. Cool stuff you have got and you keep update all of us. 먹튀검증업체

    ReplyDelete
  18. Thanks for sharing this valuable content. In my view, if all webmasters and bloggers made good content as you did, the web will be a lot more useful than ever before. 토토커뮤니티

    ReplyDelete
  19. Thank you for taking the time to publish this information very useful! 88카

    ReplyDelete
  20. This is an impressive post. Come here and take a look at my information.
    This information was very useful. I was impressed by the polite posting.
    사설검증업체

    ReplyDelete
  21. Hello. We provide helpful information in your life. Take a look and go.
    This is an impressive post. Come here and take a look at my information.
    먹튀폴리스 검증업체

    ReplyDelete
  22. This information was very useful. I was impressed by the polite posting.
    Hello. We provide helpful information in your life. Take a look and go.
    먹튀헌터

    ReplyDelete
  23. What a fantabulous post this has been. Never seen this kind of useful post. I am grateful to you and expect more number of posts like these. Thank you very much. KissAnime

    ReplyDelete
  24. Thank you so much for such a well-written article. It’s full of insightful information. Your point of view is the best among many without fail.For certain, It is one of the best blogs in my opinion. textbook answers

    ReplyDelete
  25. We stumbled over here by a different website and thought I might check things out. I like what I see so now i am following you. Look forward to finding out about your web page again. bongdo

    ReplyDelete
  26. I accidentally searched and visited your site. I still saw several posts during my visit, but the text was neat and readable. I will quote this post and post it on my blog. Would you like to visit my blog later? 토토사이트순위

    ReplyDelete

  27. This site seems to inspire me a lot. Thank you so much for organizing and providing this quality information in an easy to understand way. I think that a healthy era of big data can be maintained only when such high-quality information is continuously produced. And I, too, are working hard to organize and provide such high-quality information. It would be nice to come in once and get information.

    Also visit my site:파워볼


    ReplyDelete
  28. This site seems to inspire me a lot. Thank you so much for organizing and providing this quality information in an easy to understand way. I think that a healthy era of big data can be maintained only when such high-quality information is continuously produced. And I, too, are working hard to organize and provide such high-quality information. It would be nice to come in once and get information.

    Also visit my site:스포츠토토

    ReplyDelete
  29. I have recently started a website, the information you provide on this website has helped me greatly. Thank you for all of your time & work. 먹튀신고

    ReplyDelete
  30. I’m thinking some of my readers might find a bit of this interesting. Do you mind if I post a clip from this and link back? Thanks 안전놀이터


    ReplyDelete