Reference a variable

68 views Asked by At

I'm working on a SSIS 2012 package. Inside a foreachfile loop, there is a variable "User::Filename", a fairly standard variable for this construct. In a later step inside the loop, I move the file to an archive directory. Then, I want to rename it. I map the "Destination" property to the new name, which is of the format "" + "YYYYMMDDHHMMSS" + @[User::Filename].

When I hit "Evaluate Expression" at design time, of course it works except the Filename is null, so doesn't show. I also set "delay validation" to true.

When I run the package, it fails because it can't find either the source or the destination file (Source set the same way... + @[User::Filename].) In the error message, it shows exactly the same string I got when I hit "Evaluate Expression" at design time.

Why doesn't it show the Filename?

1

There are 1 answers

0
Metaphor On

Put a script task in the loop container with this code.

public void Main()
{
        bool success = false;
        string fName = Dts.Variables["User::Filename"].Value.ToString();
        Dts.Events.FireInformation(1, "File Loop", fName, "", 0, ref success);

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

Then look in the output window for the list printed.