Michael
Michael

Reputation: 2657

SSIS Script Task C# Only assignment and new object expressions can be used Error

I'm using a C# Script task in SSIS to check the file size of a file and compare to a variable called FileFoundSize . This is my code:

    public void Main()
    {
        string fullPath = Path.Combine(Dts.Variables["$Project::ValidationImport"].Value.ToString(), Dts.Variables["User::zipFileName"].Value.ToString());
        var fileInfo = new FileInfo(fullPath);

        if (fileInfo.Exists)
        {
            fileInfo.Length > Dts.Variables["User::FileFoundSize"];
            Dts.TaskResult = (int)ScriptResults.Success;
        }
        else
        {
            // file could not be found     
            Dts.TaskResult = (int)ScriptResults.Failure;
        }
    }

However, the editor keeps highlighting this line:

fileInfo.Length > Dts.Variables["User::FileFoundSize"];

And stating this error:

enter image description here

What am I missing?

Upvotes: 0

Views: 215

Answers (1)

Mudassir Hasan
Mudassir Hasan

Reputation: 28771

Try with below code, you missed Value property for variable

if (fileInfo.Exists)
{
        if(fileInfo.Length > Convert.ToInt32(Dts.Variables["User::FileFoundSize"].Value.ToString()))
           Dts.TaskResult = (int)ScriptResults.Success;
        else
           Dts.TaskResult = (int)ScriptResults.Failure;
}
else
{
        Dts.TaskResult = (int)ScriptResults.Failure;
}

Upvotes: 1

Related Questions