How do you copy a file Async using the following code? It appears to only work with Non-Binary files (.txt, etc.). I'd like to be able to copy any kind of file.
Shared Async Function CopyFile(inSourceFile As String,
inTargetFolder As String,
Optional inRetainDateTime As Boolean = True) As Task
ExceptionThrown = False
ExceptionDefinition = ""
Dim TargetFile As String = inTargetFolder + "\" + GSFileInfo.ParseFileName(inSourceFile, False)
Dim SourceDateTime As Date = File.GetLastWriteTime(inSourceFile)
Try
Using SourceStream As FileStream = File.Open(inSourceFile, FileMode.Open)
Using DestinationStream As FileStream = File.Create(TargetFile)
Await SourceStream.CopyToAsync(DestinationStream)
End Using
End Using
If inRetainDateTime Then
File.SetLastWriteTime(TargetFile, SourceDateTime)
End If
Catch ex As Exception
ExceptionThrown = True
ExceptionDefinition = ex.Message
End Try
End Function
ASKER
File.Open is used for text filesThat is not true. Were you thinking about File.OpenText ?
ASKER
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
ASKER
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
Replace "asInvoker" with "requireAdministrator".
ASKER
ASKER
The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.
TRUSTED BY
ASKER