SSIS Script task to check if file exists in folder or not

user1429135 picture user1429135 · Jul 10, 2013 · Viewed 71.1k times · Source

I want to check to see if a file exists in a particular folder from SSIS. How can I accomplish this?

Answer

Anoop Verma picture Anoop Verma · Jul 10, 2013

Variables:

folder - string - C::\Temp\

file - string - 1.txt

fileExists - boolean - False

public void Main()
{
    string folder = Dts.Variables["User::folder"].Value.ToString();     //@"C:\temp\";
    string file = Dts.Variables["User::file"].Value.ToString();         //"a.txt";
    string fullPath = string.Format(@"{0}\{1}", folder, file);

    Dts.Variables["User::fileExists"].Value = File.Exists(fullPath);

    Dts.TaskResult = (int)ScriptResults.Success;
}