title: How can I create a foreach loop with "Foreach From Variable Enumerator" in SSIS programmatically
body: <p>I'm trying to create an SSIS package dynamically using DTS Runtime classes.
  I'm trying to create a foreach loop using "Foreach From Variable Enumerator", where my variable contains an ArrayList with the necessary collection.</p>
  
  <p>I'm unable to find a way through which i can set the variable (under enumerator configuration, as seen in VS) which will hold the collection for looping.</p>
  
  <p>I'm not finding any options in forEachLoop.ForEachEnumerator. Nor am I able to cast forEachEnumeratorHost.InnerObject to an enumerator I want. I found on MSDN a class Microsoft.SqlServer.Dts.Runtime.Enumerators.FromVar.ForEachFromVarEnumerator. But I'm not able to find the FromVar class in Enumerators. Am i missing something grave?</p>
  
  <p>Has anyone else done this? I find it difficult to believe that something which can be done so easily through Visual Studio UI, cannot be done programmatically.</p>
  
  <p>Below is the code I have now...</p>
  
  <blockquote>
    <p>ForEachLoop forEachLoop = p.Executables.Add("STOCK:FOREACHLOOP") as
    ForEachLoop;</p>
    
    <p>// Create a VariableMappings and VariableMapping objects.<br>
      ForEachVariableMapping forEachVariableMapping =
    forEachLoop.VariableMappings.Add();</p>
    
    <p>// Create a mapping between the variable and its value.<br>
      forEachVariableMapping.VariableName = @"User::CurrentTableName";
      forEachVariableMapping.ValueIndex = 0;</p>
    
    <p>ForEachEnumeratorInfo forEachEnumeratorInfo =
    runtimeApp.ForEachEnumeratorInfos["Foreach From Variable Enumerator"];
      ForEachEnumeratorHost forEachEnumeratorHost =
    forEachEnumeratorInfo.CreateNew();</p>
  </blockquote>