C# Can';下载后不要删除文件
为什么我下载文件后不能删除它们 我得到这个错误: 文件“exfile.jpgg”,因为它正被另一个进程使用 这是我的密码C# Can';下载后不要删除文件,c#,file,download,C#,File,Download,为什么我下载文件后不能删除它们 我得到这个错误: 文件“exfile.jpgg”,因为它正被另一个进程使用 这是我的密码 string file_name = "pic.jpg" WebClient client = new WebClient(); client.DownloadFile("http://picture.com/pic.jpg", file_name); client.Dispose(); client = null; pictureBox1.Image = Image.Fr
string file_name = "pic.jpg"
WebClient client = new WebClient();
client.DownloadFile("http://picture.com/pic.jpg", file_name);
client.Dispose();
client = null;
pictureBox1.Image = Image.FromFile(File_Name);
pictureBox1.Image = null;
FileInfo MyFile = new FileInfo(File_Name);
MyFile.Delete();
听起来您需要先关闭WebClient,因为它会被锁定。也许用 WebClient.Close() or WebClient.Dispose() WebClient.Close()或WebClient.Dispose() 希望这能给你一些提示和帮助, 顺致敬意,
汤姆。你能再给我看一些代码吗。好像你从文件中读到的是
您没有关闭流/读取器。这将保留文件,不允许您删除。您可以使用来检查谁未关闭此文件。您需要处理
图像
对象
文件将保持锁定状态,直到
图像被处理
在尝试删除文件之前,您是否对该文件执行了其他操作?如果是这样,请发布代码。或者使用using指令以避免忘记关闭/处理webclient:using(webclient w=new webclient()){w.DownloadFile(“,”exfile.jpg”);}我不相信webclient有关闭方法?我正在尝试使用以下命令删除文件:FileInfo MyFile=new FileInfo(@exfile.jpg);MyFile.Delete();可能这部分有误?为什么System.IO.Path.Delete(…)?System.IO.Path不包含“Delete”的定义System.IO.File包含Delete