共用方式為


Package.SaveToXML Method (out String, IDTSEvents)

Saves the package to memory in an XML format. To save a package as .xml to the hard drive, use the Application.SaveToXml method.

命名空間: Microsoft.SqlServer.Dts.Runtime
組件: Microsoft.SqlServer.ManagedDTS (in microsoft.sqlserver.manageddts.dll)

語法

'宣告
Public Sub SaveToXML ( _
    <OutAttribute> ByRef packageXml As String, _
    events As IDTSEvents _
)
public void SaveToXML (
    out string packageXml,
    IDTSEvents events
)
public:
void SaveToXML (
    [OutAttribute] String^% packageXml, 
    IDTSEvents^ events
)
public void SaveToXML (
    /** @attribute OutAttribute() */ /** @ref */ String packageXml, 
    IDTSEvents events
)
JScript 不支援以傳址方式傳遞值類型的引數。

參數

  • packageXml
    An out parameter that contains the XML that is created when the package is saved.
  • events
    An object that implements the events to raise errors, warnings, or informational events.

備註

更新的文字:2005 年 12 月 5 日

If you want to save a package as XML to the hard drive, use the Application.SaveToXml method. If you want to save the package to the File System, use Application.SaveToDtsServer. If you want to save the package to the MSDB database, use Application.SaveToSqlServer or Application.SaveToSqlServerAs methods. When you call the Application.SaveToXml methods on the Application, the runtime will iterate through the tasks, connection managers, log providers, and all other objects that are contained by the package and call the SaveToXML method on each of them. The contained objects have code in their SaveToXML that creates an XmlElement for each property that the object must save, and a value for the element. The package contains the XmlDocument and the objects append their specific elements into the package’s XmlDocument. Therefore, you do not directly call the SaveToXML on the individual objects, but call the method on the Application object, and the runtime will cascade through the package objects and call the SaveToXML for you.

範例

The following code example creates a package and sets several package properties. The package is then saved to an in-memory XmlDocument using the SaveToXML method. Next, a new task is added to the package. The final task of the code example is to save the entire XML to a file on the hard-drive using SaveToXml.

using System;
using System.Collections.Generic;
using System.Text;  
using Microsoft.SqlServer.Dts.Runtime;
using Microsoft.SqlServer.Dts.Tasks.BulkInsertTask;
using System.Xml;

namespace SaveToXML_API
{
    class Program
    {
        static void Main(string[] args)
        {
            Application app = new Application();

            // Location and file name can be combined into one string,
            // or location could be set by a variable instead of hard-coded.
            String XmlLocation = @"C:\XML";
            String XmlFileName = "TestXML.xml";
            String XmlFile = XmlLocation + XmlFileName;
            Package pkg = new Package();
            pkg.CreatorName = "Test";
            pkg.Name = "SaveToXML Package";
            pkg.CheckSignatureOnLoad = true;
            pkg.DelayValidation = false;
            pkg.SaveCheckpoints = false;

            // Create package XmlDocument and use in pkg.SaveToXml.
            XmlDocument myPkgDocument = new XmlDocument();
            pkg.SaveToXML(ref myPkgDocument, null, null);
            // If you want to see what the package XML contains 
            // at this point, uncomment this line and view the console.
            // Console.Out.WriteLine(myPkgDocument.OuterXml);

            // Now modify the package. Create a task 
            // and set some properties.
            Executable execBI = pkg.Executables.Add("STOCK:BulkInsertTask");
            TaskHost th = execBI as TaskHost;
            th.Properties["DebugMode"].SetValue(th, false);
            // You can cast the task here.
            // BulkInsertTask myTask = th.InnerObject as BulkInsertTask;

            // Save the task into the package using pkg.SaveToXML.
            // This saves the package after it has been modified
            // by the addition of the task.
            pkg.SaveToXML(ref myPkgDocument, null, null);

            // When you want to save the package to the hard-drive,
            // Save using the Application.SaveToXML method.
            app.SaveToXml(XmlFile, pkg, null);

        }
    }
}
Imports System
Imports System.Collections.Generic
Imports System.Text  
Imports Microsoft.SqlServer.Dts.Runtime
Imports Microsoft.SqlServer.Dts.Tasks.BulkInsertTask
Imports System.Xml
 
Namespace SaveToXML_API
    Class Program
        Shared  Sub Main(ByVal args() As String)
            Dim app As Application =  New Application() 
 
            ' Location and file name can be combined into one string,
            ' or location could be set by a variable instead of hard-coded.
            Dim XmlLocation As String =  "C:\XML" 
            Dim XmlFileName As String =  "TestXML.xml" 
            Dim XmlFile As String =  XmlLocation + XmlFileName 
            Dim pkg As Package =  New Package() 
            pkg.CreatorName = "Test"
            pkg.Name = "SaveToXML Package"
            pkg.CheckSignatureOnLoad = True
            pkg.DelayValidation = False
            pkg.SaveCheckpoints = False
 
            ' Create package XmlDocument and use in pkg.SaveToXml.
            Dim myPkgDocument As XmlDocument =  New XmlDocument() 
            pkg.SaveToXML( myPkgDocument,Nothing,Nothing)
            ' If you want to see what the package XML contains 
            ' at this point, uncomment this line and view the console.
            ' Console.Out.WriteLine(myPkgDocument.OuterXml);
 
            ' Now modify the package. Create a task 
            ' and set some properties.
            Dim execBI As Executable =  pkg.Executables.Add("STOCK:BulkInsertTask") 
            Dim th As TaskHost =  execBI as TaskHost 
            th.Properties("DebugMode").SetValue(th, False)
            ' You can cast the task here.
            ' BulkInsertTask myTask = th.InnerObject as BulkInsertTask;
 
            ' Save the task into the package using pkg.SaveToXML.
            ' This saves the package after it has been modified
            ' by the addition of the task.
            pkg.SaveToXML( myPkgDocument,Nothing,Nothing)
 
            ' When you want to save the package to the hard-drive,
            ' Save using the Application.SaveToXML method.
            app.SaveToXml(XmlFile, pkg, Nothing)
 
        End Sub
    End Class
End Namespace

執行緒安全性

Any public static (Shared in Microsoft Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

平台

開發平台

如需受支援的平台清單,請參閱<安裝 SQL Server 2005 的硬體和軟體需求>。

目標平台

如需受支援的平台清單,請參閱<安裝 SQL Server 2005 的硬體和軟體需求>。

請參閱

參考

Package Class
Package Members
Microsoft.SqlServer.Dts.Runtime Namespace