question

tlenzmeier avatar image
tlenzmeier asked

Check For Files in Folder For Each Loop Container Using C# Script

I have a For Each Loop container where I process files that arrive nightly. I have three user variables defined: FolderPath ("I:\Data Analytics\Referral"), FileName (blank) -- read only variables, FileExistsFlg -- ReadWriteVariables. The first two are strings and the last one is an int. I have added "using System.IO;" to my Namespaces.The value for the FileExistsFlg is 0 -- the default value when I added the variable.

Here is my C# code:

public void Main()

// TODO: Add your code here

String FilePath = Dts.Variables["User::FolderPath"].Value.ToString() +Dts.Variables["User::FileName"].Value.ToString();

if ( File.Exists(FilePath))

{

Dts.Variables["User::FileExistsFlg"].Value = 1;

}

MessageBox.Show(FilePath); MessageBox.Show(Dts.Variables["User::FileExistsFlg"].Value.ToString());

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

The task executes, but it always returns a value of 0 when in fact there are files. I'm using MessageBox.Show(. . . .) to test the script.

This doesn't strike me as rocket science and I'm mystified why it keeps returning a false value.

Thanks.

ssisc#foreach-loop
10 |1200

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

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.