Configurations.MoveAfter Method
Moves a Configuration object after an existing Configuration object.
Assembly: Microsoft.SqlServer.ManagedDTS (in Microsoft.SqlServer.ManagedDTS.dll)
Parameters
- index
- Type: System.Object
The name, description, ID, or identity of a Configuration object that is already in the collection.
- config
- Type: Microsoft.SqlServer.Dts.Runtime.Configuration
The Configuration object to move in the collection.
Moves the Configuration object to a new position in the collection. The new position is after the object specified by the index parameter.
The following code example creates three configurations, and adds them to one package. It then displays their name, and the names are displayed in the order in which they were added. Using the MoveAfter method, the configuration in the first position, index position 0, is moved after the configuration located in index position 2. The names are again displayed, and Conf1 is now moved into position after Conf3 in the collection.
using System; using System.Collections.Generic; using System.Text; using Microsoft.SqlServer.Dts.Runtime; namespace Configurations_API { class Program { static void Main(string[] args) { Package p = new Package(); Configuration conf1 = p.Configurations.Add(); conf1.ConfigurationString = "Conf1 Configuration String"; conf1.ConfigurationType = DTSConfigurationType.EnvVariable; conf1.Description = "Some description for Conf1 configuration"; conf1.Name = "Conf1"; conf1.PackagePath = "A Variable Name in configuration Conf1"; Configuration conf2 = p.Configurations.Add(); conf2.ConfigurationString = "Conf2 Configuration String"; conf2.ConfigurationType = DTSConfigurationType.ConfigFile; conf2.Description = "Some description for Conf2 configuration"; conf2.Name = "Conf2"; conf2.PackagePath = "A Variable Name in configuration Conf2"; Configuration conf3 = p.Configurations.Add(); conf3.ConfigurationString = "Conf3 Configuration String2"; conf3.ConfigurationType = DTSConfigurationType.RegEntry; conf3.Description = "Conf3 description for Conf3 configuration2"; conf3.Name = "Conf3"; conf3.PackagePath = "A Variable Name in configuration Conf3"; DTSExecResult pkgExecResults = p.Execute(); if (pkgExecResults == DTSExecResult.Success) { Console.WriteLine("Success!"); // Iterate over the configurations. Configurations configs = p.Configurations; foreach (Configuration config in configs) { // This is an ordered collection, they display in the order added. Console.WriteLine("Configuration Name {0}", config.Name); } Console.WriteLine("---------------------------------------------------"); // Using the Configurations methods, move the configurations around. Configuration movingConfig = p.Configurations[0]; p.Configurations.MoveAfter(2, movingConfig); foreach (Configuration config in configs) { Console.WriteLine("Configuration Name {0}", config.Name); } Console.WriteLine("---------------------------------------------------"); } else { Console.WriteLine("Results were {0}", pkgExecResults); } Console.WriteLine("Number of configuration in package {0}", p.Configurations.Count); } } }
Sample Output:
Success!
Configuration Name Conf1
Configuration Name Conf2
Configuration Name Conf3
---------------------------------------------------
Configuration Name Conf2
Configuration Name Conf3
Configuration Name Conf1
---------------------------------------------------
Number of configuration in package 3
