FileSystemTask.Source 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置源文件或目录。 如果 IsSourcePathVariable 设置为 true,则获取或设置表示源文件或目录的包变量名称。
public:
property System::String ^ Source { System::String ^ get(); void set(System::String ^ value); };
public string Source { get; set; }
member this.Source : string with get, set
Public Property Source As String
属性值
一个字符串,其中包含包含源文件夹或文件信息的连接管理器或变量。
实现
示例
下面的代码示例在 FileSystemTask 包中创建一个 Executable 作为一个。 该 FileSystemTask 测试文件夹将包含两个子文件夹和一个.txt文件的测试文件夹复制到另一个文件夹。 源是现有文件夹,而不是变量,因此设置为IsSourcePathVariablefalse
该文件夹,并且属性Source设置为引用 FILE 连接管理器。
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SqlServer.Dts.Runtime;
using Microsoft.SqlServer.Dts.Tasks.FileSystemTask;
namespace FileSystemTask_API
{
class Program
{
static void Main(string[] args)
{
String sourceDir = @"C:\TestFolder";
String destDir = @"C:\MyNewTestFolder";
Package pkg = new Package();
Executable exec1 = pkg.Executables.Add("STOCK:FileSystemTask");
TaskHost th = exec1 as TaskHost;
// Show how to set properties using the TaskHost Properties.
// Set the properties to copy an existing folder, which contains two subfolders
// and a .txt file, to another existing folder on the C:\ drive.
// The source or destination files are not in a variable, so set
// IsSourcePathVariable and IsDestinationPathVariable to false.
th.Properties["IsSourcePathVariable"].SetValue(th, false);
th.Properties["IsDestinationPathVariable"].SetValue(th, false);
// Create the File connection manager for the source.
ConnectionManager cm = pkg.Connections.Add("FILE");
cm.Name = "The FILE connection manager";
cm.ConnectionString = sourceDir;
cm.Properties["FileUsageType"].SetValue(cm, DTSFileConnectionUsageType.FolderExists);
// Create the File connection manager for the destination.
ConnectionManager cmdest = pkg.Connections.Add("FILE");
cmdest.Name = "The destination FILE connection manager";
cmdest.ConnectionString = destDir;
cmdest.Properties["FileUsageType"].SetValue(cmdest, DTSFileConnectionUsageType.FolderExists);
// Set the source property and destination properties
// for the task.
th.Properties["Source"].SetValue(th, cm.Name);
th.Properties["Destination"].SetValue(th, cmdest.Name);
// The operation to perform is to copy all the files and
// subfolders in a folder.
// Do not overwrite the destination information
// if it exists.
th.Properties["Operation"].SetValue(th, DTSFileSystemOperation.CopyDirectory);
th.Properties["OperationName"].SetValue(th, "Copy TestFolder");
th.Properties["OverwriteDestinationFile"].SetValue(th, false);
// Set the attribute of the folder to be read-only.
th.Properties["Attributes"].SetValue(th, DTSFileSystemAttributes.ReadOnly);
// Multiple attributes can be set. The next line of code,
// commented out, shows how to do that.
//th.Properties["Attributes"].SetValue(th, DTSFileSystemAttributes.ReadOnly | DTSFileSystemAttributes.Hidden);
// Run the task and copy the folder.
DTSExecResult result = pkg.Execute();
}
}
}
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports Microsoft.SqlServer.Dts.Runtime
Imports Microsoft.SqlServer.Dts.Tasks.FileSystemTask
Namespace FileSystemTask_API
Class Program
Shared Sub Main(ByVal args() As String)
Dim sourceDir As String = "C:\TestFolder"
Dim destDir As String = "C:\MyNewTestFolder"
Dim pkg As Package = New Package()
Dim exec1 As Executable = pkg.Executables.Add("STOCK:FileSystemTask")
Dim th As TaskHost = exec1 as TaskHost
' Show how to set properties using the TaskHost Properties.
' Set the properties to copy an existing folder, which contains two subfolders
' and a .txt file, to another existing folder on the C:\ drive.
' The source or destination files are not in a variable, so set
' IsSourcePathVariable and IsDestinationPathVariable to false.
th.Properties("IsSourcePathVariable").SetValue(th, False)
th.Properties("IsDestinationPathVariable").SetValue(th, False)
' Create the File connection manager for the source.
Dim cm As ConnectionManager = pkg.Connections.Add("FILE")
cm.Name = "The FILE connection manager"
cm.ConnectionString = sourceDir
cm.Properties("FileUsageType").SetValue(cm, DTSFileConnectionUsageType.FolderExists)
' Create the File connection manager for the destination.
Dim cmdest As ConnectionManager = pkg.Connections.Add("FILE")
cmdest.Name = "The destination FILE connection manager"
cmdest.ConnectionString = destDir
cmdest.Properties("FileUsageType").SetValue(cmdest, DTSFileConnectionUsageType.FolderExists)
' Set the source property and destination properties
' for the task.
th.Properties("Source").SetValue(th, cm.Name)
th.Properties("Destination").SetValue(th, cmdest.Name)
' The operation to perform is to copy all the files and
' subfolders in a folder.
' Do not overwrite the destination information
' if it exists.
th.Properties("Operation").SetValue(th, DTSFileSystemOperation.CopyDirectory)
th.Properties("OperationName").SetValue(th, "Copy TestFolder")
th.Properties("OverwriteDestinationFile").SetValue(th, False)
' Set the attribute of the folder to be read-only.
th.Properties("Attributes").SetValue(th, DTSFileSystemAttributes.ReadOnly)
' Multiple attributes can be set. The next line of code,
' commented out, shows how to do that.
'th.Properties["Attributes"].SetValue(th, DTSFileSystemAttributes.ReadOnly | DTSFileSystemAttributes.Hidden);
' Run the task and copy the folder.
Dim result As DTSExecResult = pkg.Execute()
End Sub
End Class
End Namespace
注解
如果源不是变量,则源是文件连接管理器。 该 IsSourcePathVariable 属性确定它是否为变量。