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
HttpApplication State variable as a SortedList. When I add or modify one of
the files in this directory, I want to delete this HttpApplication State
variable. I tried to do this using the following lines of code in
Global.asax.vb:
Private WithEvents poemfilewatcher As New
IO.FileSystemWa tcher(HttpConte xt.Current.Serv er.MapPath("/poetry/poems/"))
Private Sub PoemDirModified (ByVal sender As Object, ByVal e As
System.IO.FileS ystemEventArgs) Handles poemfilewatcher .Changed,
poemfilewatcher .Created, poemfilewatcher .Deleted
HttpContext.Cur rent.Applicatio n.Lock()
HttpContext.Cur rent.Applicatio n.Remove("poeml ist")
HttpContext.Cur rent.Applicatio n.UnLock()
End Sub
Sub Application_Sta rt(ByVal sender As Object, ByVal e As EventArgs)
poemfilewatcher .IncludeSubdire ctories = True
poemfilewatcher .EnableRaisingE vents = True
End Sub
However, when I add, delete, or modify a file in the directory it does seem
to delete the HttpApplication State variable. Am I forgetting to do
something? Am I doing something wrong? Any help would be appreciated, or
possibly an example. Thanks.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/