question

tlenzmeier avatar image
tlenzmeier asked

Can I Pass Project Parameters In C# Script Task

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; }

ssisvariablesscript-task
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

0 Answers

· Write an Answer

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.