none
check for files at a location and send an email RRS feed

  • Question

  • hi i am looking for a process which will look at a file location (ex : c:users\lkruger\fireall) under the fire wall folder each day a file is added. I want to see the list of files (names)  sent as an email. The files will have timestamps as well so we know new file has been added. Please advice.

    Thanks

    Friday, July 19, 2019 7:10 PM

Answers

  • Hi Lisa,

    1. Create a variable called FileName, set Data Type to String.
    2. Drag a Foreach Loop Container to Control Flow, open Foreach Loop Editor. In Collection, choose Foreach File Enumerator, define your folder, choose Name and extension. In Variable Mappings, add User::FileName, set Index to 0.
    3. Drag a Script Task in Foreach Loop Container, open Script Task Editor. In ReadOnlyVariables, choose User::FileName. Then click Edit Script, please refer to the code below.
    4. Drag a Send Mail Task which connects to the Script Task, open Send Mail Task Editor, set Attachments to filename.txt and complete other settings.


    public void Main()
            {
                // TODO: Add your code here
                string fileName = "C:/Users/zoegu/Desktop/filename.txt";
                string textToAdd = Dts.Variables["FileName"].Value.ToString()+"\n";
                using (System.IO.StreamWriter writer = new System.IO.StreamWriter(fileName, true))
                {
                    writer.Write(textToAdd);
                }
                Dts.TaskResult = (int)ScriptResults.Success;
            }


    Please have a try.

    Regards,

    Zoe


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com



    Monday, July 22, 2019 6:10 AM
  • In the FOREACH loop container, loop the folder where the files are located. Use Script task to find out the file you need.

    A Fan of SSIS, SSRS and SSAS

    • Marked as answer by LisaKruger Monday, July 22, 2019 1:54 PM
    Friday, July 19, 2019 7:56 PM

All replies

  • In the FOREACH loop container, loop the folder where the files are located. Use Script task to find out the file you need.

    A Fan of SSIS, SSRS and SSAS

    • Marked as answer by LisaKruger Monday, July 22, 2019 1:54 PM
    Friday, July 19, 2019 7:56 PM
  • Hi Lisa,

    1. Create a variable called FileName, set Data Type to String.
    2. Drag a Foreach Loop Container to Control Flow, open Foreach Loop Editor. In Collection, choose Foreach File Enumerator, define your folder, choose Name and extension. In Variable Mappings, add User::FileName, set Index to 0.
    3. Drag a Script Task in Foreach Loop Container, open Script Task Editor. In ReadOnlyVariables, choose User::FileName. Then click Edit Script, please refer to the code below.
    4. Drag a Send Mail Task which connects to the Script Task, open Send Mail Task Editor, set Attachments to filename.txt and complete other settings.


    public void Main()
            {
                // TODO: Add your code here
                string fileName = "C:/Users/zoegu/Desktop/filename.txt";
                string textToAdd = Dts.Variables["FileName"].Value.ToString()+"\n";
                using (System.IO.StreamWriter writer = new System.IO.StreamWriter(fileName, true))
                {
                    writer.Write(textToAdd);
                }
                Dts.TaskResult = (int)ScriptResults.Success;
            }


    Please have a try.

    Regards,

    Zoe


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com



    Monday, July 22, 2019 6:10 AM
  • Thanks zoe and Guoxiong.
    Monday, July 22, 2019 1:54 PM