将文件复制到网络文件夹错误 [英] Copying File to the network folder Error
问题描述
大家好,
我正在尝试将文件从本地文件夹复制到网络文件夹.
当我第一次将文件复制到网络上时,我能够复制该文件,如果再次尝试复制同一文件,则会收到一条错误消息,提示该文件正在被另一个进程使用".
在再次执行相同的复制操作之前,我是否需要处置或冲洗任何东西.
谢谢与问候
Ron
Hello All,
I am trying to copy a file from my local folder to the network folder.
When i copy a file to the network for first time i am able to copy the file, if i try to copy the same file again i get a error saying " the file is being used by another process".
Do i need to dispose or flush anything before performing the same copy operation again.
Thanks and Regards
Ron
推荐答案
是的,您必须关闭源流.
您可以使用:
Yes, you have to close the source stream.
You can use:
using (Stream sourceStream = File.Open("mySourceFile.data"))
{
using (Stream targetStream = File.Create("myTargetFile.data"))
{
targetSteam.CopyFrom(sourceStream);
}
}
("using"将确保在离开该块时调用"dispose",无论是否发生异常都相等).
(请参见此处的"CopyFrom"扩展方法:使用进度报告复制流" [^ ])
(The "using" will ensure that "dispose" is called when the block is left, equal whether an exception occurred or not)
(See here for the "CopyFrom" extension method: "Copy a Stream with Progress Reporting"[^])
请从 ^ ]
希望对您有所帮助:)
Please pick one of the link from C# the file is being used by another process [^]
Hope it helps :)
这篇关于将文件复制到网络文件夹错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!