How to reset an object variable from a script task in SSIS?

I'm a bit out of date in writing an SSIS package, and I have a nested loop in my SSIS package, one of them iterates over all folders to a location, and the inner loop iterates over all the files in each folder.

In the folder level loop, my first task is a script task in which I retrieve the entire path to an object variable with a package level scope as an array of strings, as shown below.

string targetDirectory = Convert.ToString(Dts.Variables["SourceFolderLocation"].Value);
string[] fileEntries = Directory.GetFiles(targetDirectory, "*.pdf");
Dts.Variables["FileList"].Value = fileEntries;

Dts.Variables ["FileList"]. Value is my object variable with package level scope.

Now my requirement is in the script task of the folder level loop, first to reset this object variable, and then set a new list of files in this object variable, as if I received any exception from the access folder, it should not process the previous files folder.

My question is how to reset an object variable in a script c # code task? Therefore, it does not process previous folder files again, and also I do not get that the listing should not contain an error with a null value.

Any help would be greatly appreciated.

+4
source share
1 answer

, string[] GetFiles 'reset'.

string[] fileEntries = new string[] {};
try {
    string targetDirectory = Convert.ToString(Dts.Variables["SourceFolderLocation"].Value);
    fileEntries = Directory.GetFiles(targetDirectory, "*.pdf");
    Dts.Variables["FileList"].Value = fileEntries;
}
catch (Exeception e) { 
    // handle exception
}
+2

Source: https://habr.com/ru/post/1671001/


All Articles