C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » .NET Framework »

FileViewer


Posted Date: 09 Jul 2004    Resource Type: Articles    Category: .NET Framework
Author: Trishul VuppalanchiMember Level: Bronze    
Rating: 1 out of 5Points: 7



Introduction

This sample adds a systemtray icon and logs all the file activities in ur harddisk.

This sample code logs all the changes made to the textfiles.The icon in the system tray has a context menu and it helps in opening the textfile.


'Declarations
Dim strpath As String
Private ContextMenu1 As ContextMenu
Friend WithEvents menuitem1 As MenuItem
Friend WithEvents menuitem2 As MenuItem
Friend WithEvents NotifyIcon1 As NotifyIcon


'Contents of Initialize component
Me.ContextMenu1 = New ContextMenu
Me.menuitem1 = New MenuItem
Me.menuitem2 = New MenuItem
Me.ContextMenu1.MenuItems.Add(Me.menuitem1)
Me.ContextMenu1.MenuItems.Add(Me.menuitem2)

Me.menuitem1.Index() = 0
Me.menuitem1.Text = "Open"
Me.menuitem2.Index() = 1
Me.menuitem2.Text = "Exit"

Me.NotifyIcon1 = New NotifyIcon(Me.components)
NotifyIcon1.Icon = New Icon("face02.ico")
NotifyIcon1.ContextMenu = Me.ContextMenu1
NotifyIcon1.Text = "DocViewer by Trishul"
NotifyIcon1.Visible = True
call Initicon()

Private Sub InitIcon()
strpath = Application.StartupPath & "\TLOG.txt"
'File.Create(Application.StartupPath & "\inp.txt")
Dim fi As FileInfo = New FileInfo(strpath)
If fi.Exists = False Then
Dim sc As StreamWriter = New StreamWriter(File.Create(Application.StartupPath & _
"\TLOG.txt"))
sc.Close()
End If

Dim sw As StreamWriter = New StreamWriter(strpath, True)
sw.WriteLine("The Files created on " & DateTime.Now)
sw.Close()
Dim wc As New FileSystemWatcher
wc.Path = "c:\"
'wc.NotifyFilter = NotifyFilters.FileName
wc.NotifyFilter = (NotifyFilters.LastAccess Or NotifyFilters.LastWrite Or _
NotifyFilters.FileName Or NotifyFilters.DirectoryName Or _
NotifyFilters.CreationTime)
wc.Filter = "*.txt"
wc.IncludeSubdirectories = True
AddHandler wc.Created, AddressOf OnChanged
'AddHandler wc.Changed, AddressOf OnChanged
AddHandler wc.Deleted, AddressOf OnChanged
AddHandler wc.Renamed, AddressOf OnRenamed
wc.EnableRaisingEvents = True

End Sub

Private Sub OnChanged(ByVal source As Object, ByVal e As FileSystemEventArgs)
Dim sw As StreamWriter = New StreamWriter(strpath, True)
sw.WriteLine("File: " & e.FullPath & " " & e.ChangeType.ToString & _
" at " & DateTime.Now)
sw.Close()
End Sub

Private Sub OnRenamed(ByVal source As Object, ByVal e As RenamedEventArgs)
Dim sw As StreamWriter = New StreamWriter(strpath, True)
sw.WriteLine("File: " & e.OldFullPath & "renamed to " & e.FullPath & " at " & _
DateTime.Now)
sw.Close()
End Sub

Private Sub menuitem1_Click(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles menuitem1.Click
Process.Start(strpath)
Me.Hide()
End Sub

Public Shared Sub main()
Dim f1 As New Form1
Application.Run()
End Sub




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: One small Tip about Using Keyword as properties or functions......
Previous Resource: Incrementing the serial number in Datagrid Columns
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
Related Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use