Using SSIS Script Task to Check if a file exists (using C# scripting language)

i'm trying to use script task to check if a file exits. I've done this before, but it was using visual basic script. our packages are set up using C#.

this is what i have in vb (need to convert to c#)

Public Sub Main()

   Dts.Variables("v_bolFileExists").Value = File.Exists(Dts.Variables("v_zipFileArchived").Value)
   Dts.TaskResult = ScriptResults.Success

End Sub
Auerelio VasquezETL DeveloperAsked:
Who is Participating?
Brian CroweConnect With a Mentor Database AdministratorCommented:

Dts.Variables["v_bolFileExists"].Value = File.Exists(Dts.Variables["v_zipFileArchived"].Value.ToString());
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
<not an answer, but I'll throw it out in case it helps>

Pragmatic Works has a suite of custom SSIS components called Task Factory, and the File Properties task will check to see if any path-file exists, and store the result in a variable for later use.   The license is about a grand per enviroment, but if you have multiple SSIS needs chances are this product meets a bunch of them.
nishant joshiConnect With a Mentor Technology Development ConsultantCommented:
In C#,your code should below.

Dts.Variables["v_bolFileExists"].Value = System.IO.File.Exists(Dts.Variables["v_zipFileArchived"].Value.ToString());
Dts.TaskResult = (int)ScriptResults.Success;

Open in new window

Make sure that you have writable variable define in SSIS for variable "v_bolFileExists".

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.