无法访问文件,因为它被另一个进程使用 [英] Cant Access File because it is being used by another process

查看:149
本文介绍了无法访问文件,因为它被另一个进程使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ASP.NET程序,我正在使用webClient类的DownloadFile方法从Web下载文件,并对其进行一些修改。然后我将其保存到具有唯一名称的另一个文件夹。当我收到此错误


进程无法访问文件D: \RDE\\\\\\\\\\\\\\\\\\\\\\,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, $ b

任何人都可以告诉我如何解决这个问题。

解决方案

一般来说,我认为你的代码应该是这样的。

  WebClient wc = new WebClient(); 
wc.DownloadFile(http://stackoverflow.com/Content/Img/stackoverflow-logo-250.png,Foo.png);
FileStream fooStream;
using(fooStream = new FileStream(foo.png,FileMode.Open))
{
// do stuff
}
File.Move(foo .png,foo2.png);


I have an ASP.NET program where i am downloading a file from web using DownloadFile method of webClient Class and the do some modifications on it. then i am Saving it to another folder with a unique name.When I am getting this error

The process cannot access the file 'D:\RD\dotnet\abc\abcimageupload\images\TempStorage\tempImage.jpg' because it is being used by another process

Can anyone tell me how to solve this.

解决方案

Generally, I think your code should looking something like this.

WebClient wc = new WebClient();
wc.DownloadFile("http://stackoverflow.com/Content/Img/stackoverflow-logo-250.png", "Foo.png");
FileStream fooStream;
using (fooStream = new FileStream("foo.png", FileMode.Open))
{
    // do stuff
}
File.Move("foo.png", "foo2.png");

这篇关于无法访问文件,因为它被另一个进程使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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