FileSystemTask.OverwriteDestinationFile Property

 

Gets or sets a Boolean that indicates whether the task will overwrite destination files.

Namespace:   Microsoft.SqlServer.Dts.Tasks.FileSystemTask
Assembly:  Microsoft.SqlServer.FileSystemTask (in Microsoft.SqlServer.FileSystemTask.dll)

Public Property OverwriteDestinationFile As Boolean

Property Value

Type: System.Boolean

true if the task will overwrite destination files; false otherwise.

The following code example creates a FileSystemTask as an Executable in a package. The FileSystemTask copies a test folder, which contains two subfolders and a .txt file, to another folder. The sample does not overwrite any files at the destination, so OverwriteDestinationFile is set to false.

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
Return to top
Show: