SSIS Read file modification date

2019-04-29 21:02发布

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

1条回答
相关推荐>>
2楼-- · 2019-04-29 21:36

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;
    }
查看更多
登录 后发表回答