• We just launched and are currently in beta. Join us as we build and grow the community.

File Watcher - Allow or Disallow Creating Files or Folder in VB.NET

chanchalpari037

Threat Intelligence Specialist
C Rep
0
0
0
Rep
0
C Vouches
0
0
0
Vouches
0
Posts
92
Likes
197
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 200 XP
This tutorial will teach you how to create a program that will use the File Watcher component allowing files or disallow creating files or folder in vb.net.

Now, let's start this tutorial!

1. Let's start with creating a Windows Form Application for this tutorial by following the following steps in Microsoft Visual Studio: Go to File, click New Project, and choose Windows Application.

2. Next, add FileSystemWatcher in the form. Insert one textbox named TextBox1 to display the filename, a button named ButtonBrowse2 for browsing the files, button named ButtonAllow, and a button named Buttondontallow. You must design your interface like this:

filewatcher.png


3. Now, lets do the coding.

We will first code for our FileWatcher that will have the created as an event for this component.

  1. Private

    Sub

    FileSystemWatcher1_Created(

    ByVal

    sender As

    System.

    Object

    , ByVal

    e As

    System.

    IO

    .

    FileSystemEventArgs

    )

    Handles

    FileSystemWatcher1.

    Created

  2. If

    e.

    Name

    .

    Contains

    (

    "\"

    )

    =

    False

    And

    New

    FileInfo(

    e.

    FullPath

    )

    .

    Extension

    =

    Nothing

    Then

  3. Directory.

    Delete

    (

    e.

    FullPath

    )
  4. Else

  5. File.

    Delete

    (

    e.

    FullPath

    )
  6. End

    If

  7. End

    Sub

For locating or browsing files and folders, put this code in your browse button.

  1. Dim

    fbd As

    New

    FolderBrowserDialog

  2. Private

    Sub

    ButtonBrowse2_Click(

    ByVal

    sender As

    System.

    Object

    , ByVal

    e As

    System.

    EventArgs

    )

    Handles

    ButtonBrowse2.

    Click
  3. If

    fbd.

    ShowDialog

    (

    )

    =

    Windows.

    Forms

    .

    DialogResult

    .

    OK

    Then
  4. TextBox1.

    Text

    =

    fbd.

    SelectedPath
  5. End

    If
  6. End

    Sub

For allowing files or folders to be created, put this code for your allowed button. We will just use EnableRaisingEvents method of the FileWatcher to False.

  1. Private

    Sub

    ButtonAllow_Click(

    ByVal

    sender As

    System.

    Object

    , ByVal

    e As

    System.

    EventArgs

    )

    Handles

    ButtonAllow.

    Click
  2. FileSystemWatcher1.

    EnableRaisingEvents

    =

    False

  3. End

    Sub

And lastly, for disallowing files and folders to be created put this code in your disallowed button.

  1. Private

    Sub

    Buttondontallow_Click(

    ByVal

    sender As

    System.

    Object

    , ByVal

    e As

    System.

    EventArgs

    )

    Handles

    Buttondontallow.

    Click

  2. If

    Not

    TextBox1.

    Text

    =

    Nothing

    Then
  3. FileSystemWatcher1.

    Path

    =

    TextBox1.

    Text
  4. FileSystemWatcher1.

    EnableRaisingEvents

    =

    True
  5. FileSystemWatcher1.

    IncludeSubdirectories

    =

    True
  6. Else
  7. MessageBox.

    Show

    (

    "Please enter the path, you wish to monitor"

    )
  8. End

    If
  9. End

    Sub

For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below.

Best Regards,

Engr. Lyndon Bermoy
IT Instructor/System Developer/Android Developer/Freelance Programmer
Mobile: 09488225971
Landline: 826-9296
E-mail:[email protected]

Add and Follow me on Facebook: https://www.facebook.com/donzzsky

Visit and like my page on Facebook at: https://www.facebook.com/BermzISware


Download
You must upgrade your account or reply in the thread to view the hidden content.
 

452,496

335,676

335,684

Top