Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
SQL Server

How we can make File System Notification (Part 2)

Author: DevASP
Download Source Code : 548_VB.NET - File - How-To File

In This Article we will discuss How we can create the file System Notification. This topic is divided into two parts and This Article is the Part 2.

Create The New Method GetChecks. It check with Loop through all the items in the CheckedListBox, and generate an integer value corresponding to all the selected bits. Each item in the CheckedListBox is actually an integer (from an enumeration), so you simply need to convert each object into an integer, then OR it with the result.


Private Function GetChecks(ByVal clst As CheckedListBox) As Integer

        Dim intValue As Integer

        Dim obj As Object



            For Each obj In clst.CheckedItems

                intValue = intValue Or CInt(obj)


            Return intValue

        Catch exp As Exception

            MessageBox.Show(exp.Message, Me.Text)

        End Try

    End Function


Create The New Method actually Generate a unique file name, using Root as the file name root, in the specified path. For example, if Path is C:\ and Root is TempFile.txt, the procedure will attempt to return C:\TempFile.txt.00. If that file exists, it will attempt to return C:\TempFile.txt.01, incrementing the value until it finds a name that doesn't already exist.

It also Remove \ or space from the end of the path. Remove . or space from the end of the file name. Do While Loop, incrementing a counter, until you find a file that doesn't already exist. And also check If you had 100 of these files already, you'll end up overwriting .99. Sorry.


Private Function GetUniqueFileName(ByVal Path As String, ByVal Root As String) As String

        Dim strTemp As String

        Dim i As Integer


        Path = Path.TrimEnd("\ ".ToCharArray)

        Root = Root.TrimEnd(". ".ToCharArray)


            strTemp = String.Format("{0}\{1}.{2:00}", Path, Root, i)

            i += 1

        Loop While File.Exists(strTemp) And i < 100

        Return strTemp

    End Function


This one procedure can handle the Changed, Created, and Deleted events, because they all have the same event signature.  


Create New Function It Uses Loop through each item in the CheckedListBox control. For each item, if the bit corresponding to the current enumerated value is set, check the corresponding item in the list.


Private Sub HandleChangedCreatedDeleted(ByVal sender As Object, ByVal e As System.IO.FileSystemEventArgs) Handles fsw.Changed, fsw.Created, fsw.Deleted

        Dim strText As String = String.Format("{0} was {1}", e.Name, e.ChangeType)


    End Sub


Private Sub SetChecks(ByVal Value As Integer, ByVal clst As CheckedListBox)

        Dim intValue As Integer

        Dim i As Integer

        Dim blnCheck As Boolean

For i = 0 To clst.Items.Count - 1

            intValue = CInt(clst.Items(i))

            blnCheck = ((intValue And Value) = intValue)

            clst.SetItemChecked(i, blnCheck)


    End Sub


Create Function Against Delete all Button. it Delete all the files in the combo box.If you can't delete the file, it must already be deleted. Just go on.


Private Sub btnDeleteAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDeleteAll.Click

        Dim strName As String

        For Each strName In cboSampleFile.Items




            End Try




    End Sub

Running the Sample

Although this sample application uses the FileSystemWatcher component (from the Components tab on the Toolbox), this isn't required. This does make it simpler to set properties at design time, but offers no real benefits beyond that. Adding the component to a form rather than using a normal instance of the object in code makes no difference in the code, except that you can set properties at design time, and the designer takes care of creating the variable and setting .
Add Article Comment:
Name :
Email Address :
Comments :
<< How we can make File System Notification (Part 1)

Disclaimer - Privacy
© 2002-2017