Wednesday, 5 September 2018

Check file Exists in SSIS

1. Create a new script task
2. Under Script, add read only variables to file want to check exists
3. Edit Script and add the following code:

a. Under the library declaration "using Microsoft.SqlServer.Dts.Runtime;" Add the following IO:

using System.IO;

b. Replace the main method as follows

    /// <summary>
        /// Check if file exists:
        /// $Project::FolderPath,
        /// $Project::FileName
        /// </summary>
        public void Main()
        {
            string filename = Convert.ToString(Dts.Variables["FolderPath"].Value) + Convert.ToString(Dts.Variables["FileName"].Value);
            if (File.Exists(filename))
            {
                Dts.TaskResult = (int)ScriptResults.Success;
            }
            else
            {
                Dts.TaskResult = (int)ScriptResults.Failure;
            }
        }

No comments:

Post a Comment