Click here to Skip to main content
15,908,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
FileSystemWatcher fileWatcher = new FileSystemWatcher(); 
fileWatcher.Deleted += new FileSystemEventHandler(fileWatcher_FileDeleted);
private void fileWatcher_FileDeleted(object sender, FileSystemEventArgs e)
{
      writeLog(e);
}



The above code which I use to log that how many files was deleted from computer,but it will gives all files deleted from computer. But I want only those file which are deleted currently by users only not by other application or system.
Posted

1 solution

The problem is that filesytems (like NTFS) do not keep track of that information. So FileSystemWatcher alone can not provide you with the information. However, there is a workaround.

The general approach could be:

- The FileDeleted event of your FileSystemWatcher is triggered
- Start a new Task, and after a short delay, access the Security Event Log
- Find the correct entry, and read the username from there

This requires auditing to be enabled on the folder. I don't have a working example of this, but there are plenty of resources on the internet about how to access the event log and find the entry (probably using an Xpath query).
 
Share this answer
 
Comments
BharatPrajapati212 8-Sep-14 0:49am    
sir you have any solutions?
what exactly I do to solve this problem..
kbrandwijk 8-Sep-14 10:42am    
I have provided you with a way to implement a solution to your problem. However, I'm not here to write your code. Please use the resources available to you to find out how to implement the steps described, and if you have additional questions please update your question with the code you have written. Then myself and others can see if we can help you further. This link contains sample code for querying the event log: http://msdn.microsoft.com/en-us/library/bb671200.aspx. This link contains sample code of how to read event information from the result of your query: http://msdn.microsoft.com/en-us/library/bb671197.aspx

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900