Yes, But if you want to copy a big file.you should do use buffer to
copy file and retrieve information about copied file size to notify UI
progress bar.
/*----------------------- core code --------------------*/
public void Copy(string originalPath, string destinationPath)
{
using (FileStream fRStream = File.OpenRead(originalPath))
{
byte[] bytes = new byte[BufferLength];
long numBytesToRead = fRStream.Length;
using (FileStream fWStream = File.Create(destinationPath))
{
while (numBytesToRead 0L)
{
// Read may return anything from 0 to numBytesToRead.
int n = fRStream.Read(bytes, 0, bytes.Length);
// The end of the file is reached.
if (n == 0)
{
break;
}
if (n == bytes.Length)
{
// Write data the destination file.
fWStream.Write(bytes, 0, bytes.Length);
}
else
{
fWStream.Write(bytes, 0, n);
}
numBytesToRead -= (long)n;
// Notify observer
CopyingFileEventArgs e = new
CopyingFileEventArgs(fRStream.Length, fRStream.Length - numBytesToRead,
n);
OnCopying(e);
}
fWStream.Flush();
fWStream.Close();
}
}
Alan T wrote:
Is it possible to copy a file from one location to another?
eg.
from
C:\Temp\Document\TestDoc.doc
to
C:\Deploy\Document\TestDoc.doc