如何用C#覆盖winform中的文件。 [英] how to overwrite file in winform with C#.

查看:133
本文介绍了如何用C#覆盖winform中的文件。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 System.IO.File.Copy(PhotoPath +  @  \  + filename,P_Path, true ); 





< pre lang =text>我正在使用上面的行,如果文件名已经存在则替换它。但它不起作用,它不是替换...

解决方案

该代码适用于我 - true 最后允许File.Copy覆盖现有文件。



因此,它可能是权限,错误的文件路径或文件在使用问题。检查异常并查看返回的内容。例如,可能是 PhotoPath 已经包含尾随'\',因此您的源路径无效。



在这种情况下使用调试器:我们无法看到您的屏幕,访问您的硬盘或阅读您的想法,所以我们不能只给您一个解决方案!


尝试像这个



 System.IO.File.Copy(Path.Combine(PhotoPath,filename),P_Path,); 


System.IO.File.Copy(PhotoPath + @"\" + filename, P_Path, true);



i am using above line for if file name is already exist then replace it. but it is not work, it is not replace...

解决方案

That code works for me - the true at the end allows File.Copy to overwrite existing files.

So, it's probably a permissions, bad file path, or "file in use" problem. Check for exceptions and look at what is being returned. For example, it could be that PhotoPath already includes a trailing '\' so your source path is invalid.

Use the debugger in cases like this: we can't see your screen, access your HDD, or read your mind so we can't just give you a solution!


Try like this

System.IO.File.Copy(Path.Combine(PhotoPath,filename), P_Path, true);


这篇关于如何用C#覆盖winform中的文件。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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