TaskHost.InnerObject Property
Gets the method used to access the task instance being hosted by the TaskHost.
Namespace: Microsoft.SqlServer.Dts.Runtime
Assembly: Microsoft.SqlServer.ManagedDTS (in Microsoft.SqlServer.ManagedDTS.dll)
You can retrieve the specific task instance by casting the InnerObject of the TaskHost as the task type. Then you use the task's object to access its methods and properties directly.
The following code example adds a FileSystemTask and BulkInsertTask to a package and retrieves the tasks in a loop using the InnerObject method of the TaskHost to determine the task type.
using System; using System.Collections.Generic; using System.Text; using Microsoft.SqlServer.Dts.Runtime; using Microsoft.SqlServer.Dts.Tasks.BulkInsertTask; using Microsoft.SqlServer.Dts.Tasks.FileSystemTask; namespace Microsoft.SqlServer.SSIS.Samples { class Program { static void Main(string[] args) { Package p = new Package(); // Add a File System task to the package. Executable exec1 = p.Executables.Add("STOCK:FileSystemTask"); TaskHost thFileSystemTask1 = exec1 as TaskHost; // Add a Bulk Insert task to the package. Executable exec2 = p.Executables.Add("STOCK:BulkInsertTask"); TaskHost thFileSystemTask2 = exec2 as TaskHost; // Iterate through the package Executables collection. Executables pExecs = p.Executables; foreach (Executable pExec in pExecs) { TaskHost taskHost = (TaskHost)pExec; Console.WriteLine("Type {0}", taskHost.InnerObject.ToString()); if (taskHost.InnerObject is Microsoft.SqlServer.Dts.Tasks.FileSystemTask.FileSystemTask) { // Do work here. } else if (taskHost.InnerObject is Microsoft.SqlServer.Dts.Tasks.BulkInsertTask.BulkInsertTask) { // Do work here. } // Continue to add statements to check InnerObject, if desired. } } } }
Sample Output:
Type Microsoft.SqlServer.Dts.Tasks.FileSystemTask.FileSystemTask
Type Microsoft.SqlServer.Dts.Tasks.BulkInsertTask.BulkInsertTask