Package.GetPackagePath 方法

定义

返回一个值,该值包含包位置的相对路径。

public:
 virtual System::String ^ GetPackagePath();
public string GetPackagePath ();
abstract member GetPackagePath : unit -> string
override this.GetPackagePath : unit -> string
Public Function GetPackagePath () As String

返回

String

一个值,该值包含包位置的相对路径。

实现

示例

下面的代码示例演示如何检索包路径。

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

namespace Package_API  
{  
    class Program  
    {  
        static void Main(string[] args)  
        {  
            Application app = new Application();  
            Package pkg = new Package();  
            pkg = app.LoadPackage(@"C:\Program Files\Microsoft SQL Server\100\Samples\Integration Services\Package Samples\CalculatedColumns Sample\CalculatedColumns\CalculatedColumns.dtsx", null);  
            // Show the package path.  
            Console.WriteLine("Package Path: {0}", pkg.GetPackagePath());  
        }  
    }  
}  
Imports System  
Imports System.Collections.Generic  
Imports System.Text  
Imports Microsoft.SqlServer.Dts.Runtime  
Imports Microsoft.SqlServer.Dts.Tasks.ScriptTask  

Namespace Package_API  
    Class Program  
        Shared  Sub Main(ByVal args() As String)  
            Dim app As Application =  New Application()   
            Dim pkg As Package =  New Package()   
            pkg = app.LoadPackage("C:\Program Files\Microsoft SQL Server\100\Samples\Integration Services\Package Samples\CalculatedColumns Sample\CalculatedColumns\CalculatedColumns.dtsx", Nothing)  
            ' Show the package path.  
            Console.WriteLine("Package Path: {0}", pkg.GetPackagePath())  
        End Sub  
    End Class  
End Namespace  

示例输出:

Package Path: \Package

注解

有多种方法可以使用该方法 GetPackagePath 。 除了示例节中显示的方法外, GetPackagePath 还可以对包中的任何属性调用,并将路径返回到任何属性。 下面的代码示例演示对 GetPackagePath 集合第一、第二和第三个位置中的属性的 Properties 调用。

String prop = p2.Properties[0].GetPackagePath(p2);  
Console.WriteLine("Package properties path = " + prop);  

prop = p2.Properties[1].GetPackagePath(p2);  
Console.WriteLine("Package properties path = " + prop);  

prop = p2.Properties[2].GetPackagePath(p2);  
Console.WriteLine("Package properties path = " + prop);  

示例输出:

Package path = \Package

Package properties path = \Package.CertificateContext

Package properties path = \Package.CertificateObject

Package properties path = \Package.CheckpointFileName

适用于