Script task Pass a bool to a method
Hi guys, I have a method in C# that I am using in a scrip task in SSIS to determine if I have all the files required to proceed processing. The method works fine but I'd like add a bool debug flag so that I can use that in BIDS (switch on or off).In the C# method the Debug paramter is defined as a bool also in SSIS its a bool, but when I call the function I can't convert it to string since the method expects a bool...any hint to solve this? Code below: Thx Ludwig Main Proc: FileCheck MyFileCheck = new FileCheck(); MyFileCheck.FileChecker( Dts.Variables["User::Path"].Value.ToString(), Dts.Variables["User::Filter"].Value.ToString(), Dts.Variables["User::Debug"].Value); --> This is the issue. I can't convert it since the method expects a bool) How would I pass it over as a bool? Class File : using System; using System.Collections.Generic; using System.Text; using System.IO; using System.Windows.Forms; namespace ST_642c1ce958734df1acfa430997b89da9.csproj { class FileCheck { public bool FileChecker(string Path, string Filter, bool Debug) { string sourceDir = Path; string[] txtList = Directory.GetFiles(sourceDir, Filter); foreach (string f in txtList) { // Remove path from the file name. string fName = f.Substring(sourceDir.Length + 1); System.Windows.Forms. MessageBox.Show(f); //MessageBox.Show (txtList.Contains("Peter")); } //String curFile= "c:\temp\test.txt" string File1 = @"c:\Temp\Peter.txt"; string File2 = @"c:\Temp\Nicole.txt"; string File3 = @"c:\Temp\Hans.txt"; string File4 = @"c:\Temp\Miriam.txt"; bool processflag = false; if ( ( File.Exists(File1) == true) && ( File.Exists(File2) == true) && ( File.Exists(File3) == true) && ( File.Exists(File4) == true) ) { if (Debug == true) { MessageBox.Show("All Files exists");} processflag = true; } else { MessageBox.Show("At least one file is missing"); } MessageBox.Show(processflag.ToString()); return processflag; } } }
February 15th, 2011 11:43am

(bool) Dts.Variables["User::Debug"].ValueRussel Loski, MCT
Free Windows Admin Tool Kit Click here and download it now
February 15th, 2011 11:56am

There is also no need to use ToString for the string variables either. You can just inform the compiler they are strings, like this: (string)Dts.Variables["User::Path"].Value Talk to me now on
February 15th, 2011 12:51pm

Thx...that did it. L
Free Windows Admin Tool Kit Click here and download it now
February 15th, 2011 1:21pm

Thx Todd yep that's better. Thx again L
February 15th, 2011 1:22pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics