Click here to Skip to main content
12,768,041 members (43,834 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# ASP.NET
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 18-Feb-13 19:29pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.
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);

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)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170217.1 | Last Updated 19 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100