FileSystemWatcher
Heres your chance to share your own tutorials with the community. Just post them on here. If your lucky they may even be posted on the main site.
5 posts
Page 1 of 1
Hello, I'm DeveloperJacob and I want to show you one cool thing you can do with the FileSystemWatcher. It is a program that watches for events of files. So if a file is deleted, the program says that a File is delete. But we have more events than only deleted, we have: Created, Renamed, Changed and Deleted.
What you need:
2 Labels
1 Listview
2 Buttons
1 Textbox (Set to Read Only)
For the text for the buttons, labels take look at the picture: (Don't create the listview items, we are going to make them programmaticly)
For adding items to the listview I wrote this code: (Event: "Form_Load")
I have:
Deleted: Tomato
Created: Green
Changed: DarkGoldenrod
Renamed: Orange
But you may change it.
Another small but very important code:
The last code is for the checkbox: (Event: CheckedChanged)
This is the end of the tutorial.
Download the Project Files below:
What you need:
2 Labels
1 Listview
2 Buttons
1 Textbox (Set to Read Only)
For the text for the buttons, labels take look at the picture: (Don't create the listview items, we are going to make them programmaticly)
For adding items to the listview I wrote this code: (Event: "Form_Load")
Code: Select all
The next code is for the button with the text: "Browse" or "..." : ListView1.Columns.Add("Type change", 100, HorizontalAlignment.Left)
ListView1.Columns.Add("Directory", 250, HorizontalAlignment.Left)
ListView1.Columns.Add("Date / Time", 75, HorizontalAlignment.Left)
Code: Select all
For the main part of the program I wrote this code: Dim fbd As New FolderBrowserDialog
fbd.ShowDialog()
If fbd.ShowDialog = Windows.Forms.DialogResult.OK Then
TextBox1.Text = fbd.SelectedPath
FileSystemWatcher1.Path = TextBox1.Text
End If
Code: Select all
You must add this code to the Created, Renamed, Deleted and Renamed event of the FileSystemWatcher. Also you must change the text of "str(0)". On the code above the text is: "File Changed" but if you are programming the Deleted, you must change that to "File Deleted" and every event has it own color:Dim str(2) As String
Dim itm As ListViewItem
str(0) = "File Changed"
str(1) = e.FullPath
str(2) = My.Computer.Clock.LocalTime
itm = New ListViewItem(str)
itm.Name = "itmq"
itm.ForeColor = Color.DarkGoldenrod
ListView1.Items.Add(itm)
I have:
Deleted: Tomato
Created: Green
Changed: DarkGoldenrod
Renamed: Orange
But you may change it.
Another small but very important code:
Code: Select all
The code is for setting the Path of the FileSystemWatcher.FileSystemWatcher1.Path = TextBox1.Text
The last code is for the checkbox: (Event: CheckedChanged)
Code: Select all
If TextBox1.Text = "" Then
CheckBox1.CheckState = CheckState.Checked
MsgBox("You must select a path first.")
Else
If CheckBox1.Checked = True Then
FileSystemWatcher1.IncludeSubdirectories = True
ElseIf CheckBox1.Checked = False Then
FileSystemWatcher1.IncludeSubdirectories = False
End If
End If
This is the end of the tutorial.
Download the Project Files below:
You do not have the required permissions to view the files attached to this post.
Last edited by DeveloperJacob on Sat Jul 14, 2012 3:41 pm, edited 1 time in total.
Hello nice post and all but i have seen so many of these on youtube and throughout google 5 credits is a bit much for one of these other than that nice first post.
<a href="http://www.points2shop.com/s/xbox_point ... 5082"><img src="http://points2shop.com/images/promotion ... ricoxg.gif" border="0"/></a>
pip wrote:Hello nice post and all but i have seen so many of these on youtube and throughout google 5 credits is a bit much for one of these other than that nice first post.Thanks for your reply! I will change the price.
This is a very nice tutorial. It's your first one, isn't it? Welcome to the site, if we haven't already welcomed you lol, and +rep for this nice tut ;)
comathi wrote:This is a very nice tutorial. It's your first one, isn't it? Welcome to the site, if we haven't already welcomed you lol, and +rep for this nice tut ;)Yes it's my first tutorial and Thankyou for your reply!
5 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023