Informant : A file system watcher utility
As the name suggests, FileSystemWatcher class from System.IO namespace is a need at times when you need to observe a change at a given file system location. The change may be file creation, file deletion, file rename, etc. I came across such a need today when I had to identify where a temperory file is created by an application during execution. So I wrote down a utility using above class. Later when I was done I thought of extending the utility so that it might help someone else,
Using the utility you can configure to monitor following,- Name of the file
- Name of the directory
- Attribute of the file or folder
- Size of the file or folder
- Date of modification
- Date of access
- Time of file or folder creation
You can log the changes with username and time of event, traverse subdirectories to be monitored, view the graphical representation of file system location being monitored and most important of all, select to play the application in system tray where it will report an event as soon as it occurs as shown in the figure,
Important snippets from code are presented below,
Protected Sub ParseFolderStructure(ByVal folderPath As String, ByVal treeNode As TreeNode)Try
Dim dirInfo As New IO.DirectoryInfo(folderPath)
Dim fileObject As FileSystemInfo
For Each fileObject In dirInfo.GetFileSystemInfos()
If (fileObject.Attributes And FileAttributes.Directory) = FileAttributes.Directory Then
If chkIncludeSubdirectories.Checked Then
treeNode.Nodes.Add(fileObject.FullName, fileObject.FullName, 0)
ParseFolderStructure(fileObject.FullName, treeNode.Nodes.Add(fileObject.FullName))
End If
Else
treeNode.Nodes.Add(fileObject.FullName, fileObject.FullName, 1)
End If
Next
Catch
Throw
End Try
End Sub
FolderWatcher object instantiation to look for a given path,
FileSystemWatcher objFileSystemWatcher = New FileSystemWatcher()objFileSystemWatcher.Path = Me.txtUri.Text
objFileSystemWatcher.EnableRaisingEvents = TrueEvent handlers association for various events,
objFileSystemWatcher.IncludeSubdirectories = False
AddHandler objFileSystemWatcher.Changed, AddressOf LogChange
AddHandler objFileSystemWatcher.Created, AddressOf LogChange
AddHandler objFileSystemWatcher.Deleted, AddressOf LogChange
AddHandler objFileSystemWatcher.Renamed, AddressOf LogRename
objFileSystemWatcher.NotifyFilter = IO.NotifyFilters.DirectoryName
objFileSystemWatcher.NotifyFilter = objFileSystemWatcher.NotifyFilter Or IO.NotifyFilters.Attributes
objFileSystemWatcher.NotifyFilter = objFileSystemWatcher.NotifyFilter Or IO.NotifyFilters.Size
objFileSystemWatcher.NotifyFilter = objFileSystemWatcher.NotifyFilter Or IO.NotifyFilters.LastWrite
objFileSystemWatcher.NotifyFilter = objFileSystemWatcher.NotifyFilter Or IO.NotifyFilters.LastAccess
objFileSystemWatcher.NotifyFilter = objFileSystemWatcher.NotifyFilter Or IO.NotifyFilters.CreationTime
objFileSystemWatcher.NotifyFilter = objFileSystemWatcher.NotifyFilter Or IO.NotifyFilters.Securityand showing a balloon tooltip upon activity for log change, Protected Sub LogChange(ByVal source As Object, ByVal e As System.IO.FileSystemEventArgs)
Me.NotifyIcon1.BalloonTipTitle = "Activity Monitored"
Dim msg As String = "File " & e.FullPath & " was deleted"
Me.NotifyIcon1.BalloonTipText = msg
NotifyIcon1.ShowBalloonTip(2000)
End Sub
Download executable: http://usmanahmed.info/downloads/informant.zip
Download source code: http://usmanahmed.info/downloads/informant-source.zip [Visual Studio 2008 using VB .net]
About Me
Usman ur Rehman Ahmedis known as a software engineer in Lahore, Pakistan. He is renowned for having an abstract understanding of vast range of technological developments such as programming languages, web development, RIA's and documental writing, and is mainly specialized in developmental analysis.
Tags
- windows phone 7 (15)
- DNN (14)
- Dot Net Nuke (13)
- .NET (5)
- c# (5)
- manifest (4)
- Application (3)
- MySql (3)
- Provider (3)
- Sql (3)
- View all 237 tags »
- Sql Server (3)
- Stored Procedure (3)
- visual sutdio (3)
- API (2)
- Data (2)
- Mango (2)
- Module (2)
- Permission (2)
- PhoneTextBlock (2)
- User Control (2)
- Windows (2)
- config (2)
- console (2)
- developer (2)
- dot net (2)
- emulator (2)
- enumeration (2)
- expression blend (2)
- extension (2)
- loop (2)
- network (2)
- phone 7 (2)
- tools (2)
- transparent (2)
- .ascx (1)
- 3g (1)
- 5.6.2 (1)
- 7.1 (1)
- 7.5 (1)
- AJAX (1)
- Activity (1)
- App.xaml (1)
- AppManifest (1)
- ApplicationIcon (1)
- Arabic (1)
- Background.png (1)
- BuildAction (1)
- Connector (1)
- Control Panel (1)
- Core Version (1)
- Data-tier (1)
- DataBound (1)
- Database (1)
- Dependency (1)
- DeviceNetworkInterface (1)
- Directory (1)
- Dynamic (1)
- EVDO (1)
- Encryption (1)
- File (1)
- FileSystemWatcher (1)
- Filter (1)
- Foreign Key (1)
- Function (1)
- GUID (1)
- GetSiteLog (1)
- Hash (1)
- Host Settings (1)
- IIS6 (1)
- IIS7 (1)
- Integrated Mode (1)
- Internet Explorer (1)
- IsolatedStorage (1)
- Java (1)
- Koder (1)
- Linq (1)
- Lists (1)
- Log (1)
- Marketplace (1)
- Membership (1)
- Microsoft (1)
- NavigationCacheMode (1)
- NavigationContext (1)
- NavigationService (1)
- Notify (1)
- OnClientNodeChecked (1)
- PTCL (1)
- Panaroma (1)
- Password (1)
- Properties (1)
- Query String (1)
- ResXResourceReader (1)
- ResolveHostNameAsync (1)
- Right to Left (1)
- SDK (1)
- SEO (1)
- SendKeys (1)
- SendWait (1)
- SharpPCap (1)
- Stream (1)
