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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.
Brian CroweDatabase AdministratorCommented:

Dts.Variables["v_bolFileExists"].Value = File.Exists(Dts.Variables["v_zipFileArchived"].Value.ToString());

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nishant joshiTechnology 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".

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.