Help with FileSystemWatcher

Discussion in 'ASP .Net' started by Nathan Sokalski, Apr 8, 2006.

  1. I have a directory on my site that I keep a bunch of text files in. The
    Application keeps the first line of each of these files in an
    HttpApplicationState variable as a SortedList. When I add or modify one of
    the files in this directory, I want to delete this HttpApplicationState
    variable. I tried to do this using the following lines of code in
    Global.asax.vb:

    Private WithEvents poemfilewatcher As New
    IO.FileSystemWatcher(HttpContext.Current.Server.MapPath("/poetry/poems/"))


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

    HttpContext.Current.Application.Lock()

    HttpContext.Current.Application.Remove("poemlist")

    HttpContext.Current.Application.UnLock()

    End Sub


    Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)

    poemfilewatcher.IncludeSubdirectories = True

    poemfilewatcher.EnableRaisingEvents = True



    End Sub


    However, when I add, delete, or modify a file in the directory it does seem
    to delete the HttpApplicationState variable. Am I forgetting to do
    something? Am I doing something wrong? Any help would be appreciated, or
    possibly an example. Thanks.
    --
    Nathan Sokalski

    http://www.nathansokalski.com/
    Nathan Sokalski, Apr 8, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tushar

    FileSystemWatcher Created() delay

    Tushar, Jan 20, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    5,743
    Tushar
    Jan 20, 2006
  2. Sacha Korell

    FileSystemWatcher in Web Application

    Sacha Korell, Sep 4, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    2,204
    Sacha Korell
    Sep 4, 2003
  3. NBB
    Replies:
    2
    Views:
    8,901
  4. Jon Maz
    Replies:
    3
    Views:
    7,548
    Jon Maz
    Oct 20, 2004
  5. J-T
    Replies:
    20
    Views:
    8,102
Loading...

Share This Page