SSIS: Script for Finding a file in a given path and verifying whether the file is existing or not

In order to find out whether a given file is in appropriate place and if the file exists verifying whether the file contains the data or not. In this post we will discuss how to check that.

Create a Package and create the variables:

SourceFilePath – Contains the path of the folder where the file exists

SourceFile – Contains the name of the file that we are checking

Take Script Task in SSIS and  type the following in the script task

string path = Dts.Variables["SourceFilePath"].Value.ToString() + Dts.Variables["SourceFile"].Value.ToString();

            //Verifying the existance of file in the path

            if (File.Exists(path))

            {

                //Verifying the existance of data in the file

                FileInfo inputFile = new FileInfo(path);

                long lngFileLength = inputFile.Length;

                if (lngFileLength > 0 )

                {

                    Dts.Variables["User::Datachk"].Value = true;

                }

                else

                {

                    Dts.Variables["User::Datachk"].Value = false;

                    Dts .Variables ["User::MailMsg"].Value = "The Feed File is empty." ;

                }

            }

            else

            {

                Dts.Variables["User::Datachk"].Value = false;

                Dts.Variables["User::MailMsg"].Value = "The Feed File is not in the correct path, please place the file in the path and execute package.";

            }
Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: