c#.net中的file.copy方法问题 [英] file.copy method issue in c#.net

查看:230
本文介绍了c#.net中的file.copy方法问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



请帮帮我,我有file.copy方法的问题。问题是,当我第一次从文件上传控件上传文件时它正常工作但下次我使用相同的控件来复制新文件时,它的工作对于小尺寸文件,但比现有文件大小更重要在服务器上复制。





提前致谢......

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

推荐答案

File.Copy()不适合复制LARGE文件。这通常很好用,你可以在使用时使用状态栏和各种东西,但是,它显然不适合与大文件一起使用。而不是那样,你可以继续进行异步文件复制。

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







- 发送




--Amit


这篇关于c#.net中的file.copy方法问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆