Copying files in C#
And for my last trick question of the week :)
I am attempting to copy files from one directory (given as a parameter), to the TEMP directory on the user's system. I have found the System.IO.File object, and read about using streams to accomplish this.
However, I am an old-hand VB programmer and am used to simply using direct file system object calls to the API asking for a file to be copied from point A to point B.
Is there any way to accomplish the direct copy of a file using API calls to certain paths, or do I need to use streams as a go-between.
Thanks again, this board is turning out to be a great resource!
-Tree!
FIrst of all, I suggest that you take some time to "get over" the urge to use API calls to get information and to perform tasks. If at all possible, look for a solution within the .NET Framework. For example, to get the Temp path, you might want to use the Path.GetTempPath method, rather than the Win32 API.
As for copying files, the shared File.Copy method can do the job, as in:
System.IO.File.Copy("SourceFile", "DestinationFile")
Or, if you add an Imports statement to the top of the file, you can use:
Imports System.IO
' then, in your code:
File.Copy("SourceFile", "DestinationFile")