Quantcast
Channel: Questions in topic: "variables"
Viewing all articles
Browse latest Browse all 49

Can I Pass Project Parameters In C# Script Task

$
0
0

I have a script task I'm executing in an SSIS package. If I use a User::Folder variable that is defined in the variables as a string value, the task runs fine. However, when I try to define the same string using a project-level variable @[$Project::CPS_Referral_Csv_Pkg], the script task throws a run time error.

Here's the C# script:

// TODO: Add your code here

Boolean FileExists;
String FolderName = (String)Dts.Variables["Folder"].Value.ToString();

try
{
var txtFiles = Directory.EnumerateFiles(FolderName, "*.csv");
int fileCount = 0; foreach (string currentFile in txtFiles) { fileCount++;
}
FileExists = false; if (fileCount > 0)
{
FileExists = true;
}
Dts.Variables["FileExistsFlg"].Value = FileExists;
}
catch (Exception e)
{
Dts.Events.FireError(0, "ERROR", e.Message, null, 0);
Dts.Events.FireError(0, "ERROR", e.InnerException.Message, null, 0);
Dts.TaskResult = (int)ScriptResults.Failure; }


Viewing all articles
Browse latest Browse all 49

Trending Articles