Click here to Skip to main content
15,897,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

Please help me, i have issue with file.copy method. Issue is, when i upload the file from file upload control at first time it's work proper but next time i use the same control to copy the new file, its work for small size file, but grater than existing file size its not copy on server.


Thanks in advance......
Posted

1 solution

File.Copy() is not good for copying LARGE files. This works great normally and you can do status bars and all kinds of stuff when using it, however, it was clearly not designed to work gracefully with large files. Instead of that, you can go ahead with asynch file copying.
C#
public void CopyFile(string source, string dest)
{
    using (FileStream sourceStream = new FileStream(source, FileMode.Open))
    {
        byte[] buffer = new byte[64 * 1024]; // Change to suitable size after testing performance
        using (FileStream destStream = new FileStream(dest, FileMode.Create))
        {
            int i;
            while ((i = sourceStream.Read(buffer, 0, buffer.Length)) > 0)
            {
                destStream.Write(buffer, 0, i);
                OnProgress(sourceStream.Position, sourceStream.Length);
            }
        }
    }
}



--Amit
 
Share this answer
 
v2
Comments
dA.d 19-Feb-13 1:35am    
Thanks for you quick replay,
my code work on local machine but on server shows the error of "ScriptResource.axd?d=" like this u have any solution for this please suggest me...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900