Delete open file c#




















I need to delete the files even if its listed in second users combobox, as I have another logic that doesn't allow the user to select the combobox item selected by first user. The error is caused because of same filename in another folder As I have images in all the folders with same names, but different images , it's not caused due to the folder being tried to delete. If user selects the batch that's already deleted, I have logic in place to check if that particular directory no longer exists remove from combobox and move to next batch or first batch if deleted item was last one.

Copy Code. Posted Jan am Member Add a Solution. Work for me, thank you. Top Rated Most Recent. Accept Solution Reject Solution. Like the error says, you cannot delete a file that is in use by any process nor can you delete a folder which has a file open in it. The comboboxes have nothing at all to do with this. The files are actually in use by some process. You cannot delete them until the every process that has the file open closes it.

Posted Jan pm Dave Kreskowiak. Member 1-Feb am. The error is caused because of same filename in another folder As I have images in all the folders with same names , it's not caused due to the folder being tried to delete.

About the application crashing I have logic in place to check if that particular directory no longer exists remove from combobox and move to next batch or first batch if deleted item was last one. Dave Kreskowiak 1-Feb pm. In the context of your original post, your comment made absolutely no sense at all.

Member 1-Feb pm. I realized that today, I added that to the question as well. Thanks for your response. Rob Philpott 1-Feb pm. That's interesting. How would one delete a file in use by another process?

I'm not saying. The real "I gotta have" people will Google for it. Just a warning, it ain't pretty. FileInfo , and System. DirectoryInfo classes from the System.

IO namespace. These examples do not provide a progress bar or any other user interface. If you want to provide a standard progress dialog box, see How to provide a progress dialog box for file operations. Use System. FileSystemWatcher to provide events that will enable you to calculate the progress when operating on multiple files. Another approach is to use platform invoke to call the relevant file-related methods in the Windows Shell.

Below are the programs to illustrate the File. Delete String method. Program 1: Before running the below code, a file file. IO namespaces using System; using System.

Delete myfile1 ; File. WriteLine "Specified files have been deleted. After running the above code, above output is shown and two existing files file. Skip to content. Change Language. Related Articles. Table of Contents. Improve Article. Save Article. Like Article. Last Updated : 12 Apr, IO namespaces. Delete myfile ;.



0コメント

  • 1000 / 1000