Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SSIS Read file modification date

We have an SSIS process that imports various files in different formats from various sources. Each of these files is delivered at different times throughout the month.

The users would like to be able to see the modification date for each file, to check they are getting regular updates.

The aim would be to produce a table at the end of the process like this:

Desired Table

So I am trying to work out how to get the modification date of each of the files I have read in. Is there a way to do this in SSIS ?

Thanks in advance

like image 755
Lobsterpants Avatar asked Jul 22 '15 07:07

Lobsterpants


1 Answers

You can add a script component to the pipeline which reads the filename from an input variable and writes the file modified date to an output variable:

    /// <summary>
    /// This method is called when this script task executes in the control flow.
    /// Before returning from this method, set the value of Dts.TaskResult to indicate success or failure.
    /// To open Help, press F1.
    /// </summary>
    public void Main()
    {
        System.IO.FileInfo theFile = 
              new System.IO.FileInfo(Dts.Variables["User::FilePath"].Value.ToString());

        if (theFile.Exists)
        {
            Dts.Variables["User::LastFileDate"].Value = theFile.LastWriteTime;
        }
        Dts.TaskResult = (int)ScriptResults.Success;
    }
like image 96
Steve Ford Avatar answered Oct 15 '22 02:10

Steve Ford