如何使用c#代码刷新任何文件夹 [英] How can refresh any folder with c# code

查看:107
本文介绍了如何使用c#代码刷新任何文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Friends,



我正在开发一个窗口应用程序。我这个应用程序我通过网络摄像头拍照,我也通过代码保存该图像。保存后,Image i调整了图像H和W的大小,并从目录文件路径中删除了旧的Image文件。窗口.net控件的ImageBox中新的Image重新加载。但保存在数据库中的图像文件后,我再次想要从我保存为临时的文件夹中删除该图像。我也清楚这样的图像路径我正在使用路径来保存图像



Hello Friends,

I am developing a window application. I this app i am taking a photo via webcame and i save that image by code too. after save that Image i resized the image H and W. and also delete the old Image file from directory file path. the new Image reload in ImageBox of window .net control. but after save that Image file in data base i am again want to delete that image from that folder where i save for Temporary. i am also clear the image path like this I''m Using the Path to save image

"C:\\Users\\Public\\Pictures\\Sample Pictures\\"







pictureBox.ImageLocation =""





但是我得到了一个名为path的Exception,你可以删除这个文件

请帮帮我怎样才能刷新这条路径





but i got a Exception which called path is in used you can able to delete this file
please help me how can i refresh the this path

"C:\\Users\\Public\\Pictures\\Sample Pictures\\"





从这条路径轻松删除文件..



谢谢



to delete the file easily from this path..

Thank You

推荐答案

这并不像你想象的那么简单摆脱正在使用的文件错误 - 问题通常是使用该文件并阻止您删除它的应用程序,是试图删除的应用程序。



对于将图像复制到其他位置或数据库的应用程序来说,这通常是一个问题。



问题就是当你读取文件数据时,如果你没有正确关闭和处理所有流,图像和你加载的临时数据等,它将一直使用,直到垃圾收集器决定不再需要它。这可能是在一个小时的时间,或下周!



查看您的加载代码:检查访问该文件的所有内容是否正确处置,或包含在使用 block。
It''s not as simple as you may think to get rid of the "file in use" error - the problem is very often that the application that is using the file and preventing you from deleting it, is the application that is trying to do the delete.

And this is very often a problem with applications that copy images to other locations, or into databases.

The problem is that when you read the file data, if you do not properly close and dispose of all the streams, images and such like temporary data you load, it remains in use until the Garbage Collector decides it is not needed any more. This could be in an hours time, or next week!

Look at your loading code: check that everything that accesses the file is correctly Disposed, or enclosed in a using block.


这篇关于如何使用c#代码刷新任何文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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