Package.ExportConfigurationFile Method (String)


Creates an XML file that contains all deployable variables in the package.

Namespace:   Microsoft.SqlServer.Dts.Runtime
Assembly:  Microsoft.SqlServer.ManagedDTS (in Microsoft.SqlServer.ManagedDTS.dll)

public void ExportConfigurationFile(
	string str


Type: System.String

The path to the configuration file.

You can edit the configuration file and change the values for the computer-dependent variables. Each time the package is deployed to a different computer, it will use the computer-dependent variables on that computer when executing. For more information, see Create Package Configurations.

The following example creates a new package, sets EnableConfigurations to true, and sets the ExportConfigurationFile property. The example then adds a new configuration to the package and sets the value of the ConfigurationString, ConfigurationType, and PackagePath.

static void Main(string[] args)
            // Create a package and set two properties.
            Package pkg = new Package();
            pkg.EnableConfigurations = true;

            // Create a variable object and add it to the 
            // package Variables collection.
            Variable varPkg = pkg.Variables.Add("var", false, "", 100);
            varPkg.Value = 1;
            string packagePathToVariable = varPkg.GetPackagePath();

            // Create a configuration object and add it to the 
           // package configuration collection
            Configuration config = pkg.Configurations.Add();

           // Set properties on the configuration object.
            config.ConfigurationString = "conf.xml";
            config.ConfigurationType = DTSConfigurationType.ConfigFile;
            config.PackagePath = packagePathToVariable;

            //save the package and its configuration
            Application app = new Application();
            app.SaveToXml(@"c:\pkg.xml", pkg, null);

            //Reload the package
            Package p1 = app.LoadPackage(@"c:\pkg.xml", null);
            //Review its Variables collection
            Console.WriteLine("The value of variable VAR = " + p1.Variables["var"].Value);

Sample Output:

The value of variable VAR = 1

Return to top