View Single Post
  #10 (permalink)  
Old March 9th, 2004, 09:39 AM
meinken meinken is offline
Registered User
Join Date: Dec 2003
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts

Okay, I understand that. Now how about this? I use no page_load event, only "clickable" events. Still no go...

<%@ Page Language="VB" Debug="True" %>
<%@ import Namespace="System.IO" %>
<%@ import Namespace="System.Diagnostics" %>
<script runat="server">

              Public watchfolder As FileSystemWatcher

              Public objFSO = Server.CreateObject("Scripting.FileSystemObject")

              Public Sub btn_start_Click(sender As Object, e As EventArgs)
                 watchfolder = New System.IO.FileSystemWatcher()

    ' if objfso.FileExists(txt_watchpath.Text) Then
                  if objfso.FolderExists(txt_watchpath.Text) Then
                    'this is the path we want to monitor
                     watchfolder.Path = txt_watchpath.Text
                     txt_folderactivity.Text &= "Monitor Started...." & vbCrLf
                     txt_folderactivity.Text &= " Watching " & txt_watchpath.Text & "...." & vbCrLf

                  'Add a list of Filter we want to specify make sure you use OR for each Filter as we need to
                  'include all of those

                     watchfolder.NotifyFilter = IO.NotifyFilters.DirectoryName
                     watchfolder.NotifyFilter = watchfolder.NotifyFilter Or IO.NotifyFilters.FileName
                     watchfolder.NotifyFilter = watchfolder.NotifyFilter Or IO.NotifyFilters.Attributes

                  ' add the handler to each event
                     AddHandler watchfolder.Changed, AddressOf logchange
                     AddHandler watchfolder.Created, AddressOf logchange
                     AddHandler watchfolder.Deleted, AddressOf logchange
                  ' add the rename handler as the signature is different
                     AddHandler watchfolder.Renamed, AddressOf logrename

                     watchfolder.IncludeSubdirectories = False
                     watchfolder.EnableRaisingEvents = True
                   'Set this property to true to start watching
                     btn_startwatch.Enabled = False
                     btn_stop.Enabled = True
                     txt_folderactivity.Text = "Invalid directory: " & txt_watchpath.Text & ". Re-enter"
                  end if
              End Sub

              Public Sub btn_stop_Click(sender As Object, e As EventArgs)
                 txt_folderactivity.Text &= "Monitor Stopped..." & vbCrLf
                 watchfolder = New System.IO.FileSystemWatcher()
                 watchfolder.EnableRaisingEvents = False
                 btn_startwatch.Enabled = True
                 btn_stop.Enabled = False
              End Sub

              Public Sub logchange(ByVal source As Object, ByVal e As System.IO.FileSystemEventArgs)
                 txt_folderactivity.Text &= "***Event Fired!***"

                 If e.ChangeType = IO.WatcherChangeTypes.Changed Then
                    txt_folderactivity.Text &= "File " & e.FullPath & " has been modified" & vbCrLf
                 End If

                 If e.ChangeType = IO.WatcherChangeTypes.Created Then
                    txt_folderactivity.Text &= "File " & e.FullPath & " has been created" & vbCrLf
                 End If

                 If e.ChangeType = IO.WatcherChangeTypes.Deleted Then
                    txt_folderactivity.Text &= "File " & e.FullPath & " has been deleted" & vbCrLf
                 End If
              End Sub

              Public Sub logrename(ByVal source As Object, ByVal e As System.IO.RenamedEventArgs)
                  txt_folderactivity.Text &= "File" & e.OldName & " has been renamed to " & e.Name & vbCrLf
              End Sub

    <form runat="server">
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
            <asp:Button id="btn_startwatch" onclick="btn_start_Click" runat="server" Text="Start Watching"></asp:Button>
            Type Folder to Watch:&nbsp;
            <asp:TextBox id="txt_watchpath" runat="server" Width="323px"></asp:TextBox>
            <asp:Button id="btn_stop" onclick="btn_stop_Click" runat="server" Text="Stop Watching"></asp:Button>
            Folder Activity:
            <asp:TextBox id="txt_folderactivity" runat="server" Width="759px" Height="409px" TextMode="MultiLine"></asp:TextBox>

Reply With Quote