File.Move访问问题 [英] File.Move Access Issue

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

问题描述

我正在尝试移动文件,但是我收到一个异常,说明该文件因为正在使用而无法移动。我意识到这是一个常见错误,而且我的应用程序是保持文件打开的应用程序,但我不知道的是在哪里。


我正在使用Html Agility Pack打开文件(.html),它有一个.Load方法。我知道,打开后没有办法卸载或关闭文档。除此之外,我从.html文档中抓取了一些数据,但不是很多。我也从.html文件的链接下载文件(使用webclient),但我也无法移动该文件。请注意下面的代码。

I am attempting to move a file, but I am receiving an exception stating that the file cannot be moved because it is in use. I realize this is a common error, and also that my application is the one that is keeping the file open, but what I don''t know is where.

I am opening the file (.html) using the Html Agility Pack, which has a .Load method. There is not a way, that I know of, to unload or close a document once open. Other than that, I scrape some data from the .html document but not a lot more. I am also downloading a file (using webclient) from a link from the .html file, but I cannot move that file either. Note my code below.

展开 | 选择 | Wrap | 行号

推荐答案

如果Agility包正在加载文件并且不允许你卸载它并且那就是导致锁定的原因,那么我的观点是你需要抛弃敏捷包并使用更高效的东西...或者你需要通过电子邮件发送给生产者这个包让他们知道他们的API有一个短缺需要在短时间内解决。


你是如何准确地抓取文件的?在过去,无论格式如何,我总是使用正则表达式来抓取文件。这样可以在应用程序中实现更高级别的控制,这意味着您可以控制何时打开和关闭文件。
If the Agility pack is loading the file and not allowing you to unload it and that''s what''s causing the lock, then my view is that you need to ditch the agility pack and use something more productive... either that or you need to email the producers of this pack and let them know that there''s a shortfall in their API that needs addressing in short order.

How are you scraping the file exactly? In the past, I''ve always used something Regular Expressions to scrape files, regardless of the format. This allows a far greater level of control in your application meaning that you can control when files are open and closed.


使用敏捷包,我可以将所有类似的标记收集到一个数组中,然后选择我需要使用哪一个。我简要介绍了使用正则表达式来解析html,但我对Html Agility Pack的易用性非常满意。
With the agility pack, I can collect all similar tags into an array, and then just select which one I need to use. I briefly looked at using regular expressions to parse the html, but I was very pleased with the ease of use of the Html Agility Pack.


我还应该注意到我无法移动我用WebClient下载的文件。即使我调用WebClient.Dispose(),我也无法访问该文件。
I should also note that I am not able to move the file I download with WebClient. Even if I call WebClient.Dispose(), I cannot gain access to the file.


这篇关于File.Move访问问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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