Mattisc 0 Newbie Poster

Hello,

I have created a filesystemwatch function to check a folder on the C drive for changes to files. I then want to output it to a multiline textbox or a listview but having problesm doing so. I have tried different ways to output it but with out any luck. Any ideas on how I can do this?

I am developing in .NET and Visual Studio 2010.

[IODescriptionAttribute("FileSystemWatcherDesc")]
    [PermissionSetAttribute(SecurityAction.LinkDemand, Name = "FullTrust")]
    [PermissionSetAttribute(SecurityAction.InheritanceDemand, Name = "FullTrust")]

    public void CreateWatcher()
    {
        try
        {
            FileSystemWatcher watcher = new FileSystemWatcher();

            watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
               | NotifyFilters.FileName | NotifyFilters.DirectoryName;

            watcher.Path = @"C:\Uploads";
            watcher.Renamed += new RenamedEventHandler(watcher_Renamed);
            watcher.Deleted += new FileSystemEventHandler(watcher_Deleted);
            watcher.Changed += new FileSystemEventHandler(watcher_Changed);
            watcher.Created += new FileSystemEventHandler(watcher_Created);
            watcher.EnableRaisingEvents = true;
            Label4.Text = "Monitor is on";
        }
        catch (Exception ex)
        {
            Label4.Text = "ERROR: " + ex.Message.ToString();
        }
    }

    void watcher_Renamed(object sender, RenamedEventArgs e)
    {
        ListBox1.Text += e.ChangeType + ": " + e.OldFullPath + " renamed to " + e.FullPath;       
    }

    void watcher_Deleted(object sender, FileSystemEventArgs e)
    {
        ListBox1.Text += e.ChangeType + ": " + e.FullPath + "\r\n";                
    }

    void watcher_Changed(object sender, FileSystemEventArgs e)
    {
        string log = string.Format("{0:G} | {1} | {2}"
        , DateTime.Now, e.FullPath, e.ChangeType);
        ListBox1.Items.Add(log);
      
    }

    void watcher_Created(object sender, FileSystemEventArgs e)
    {
        ListBox1.Text += e.ChangeType + ": " + e.FullPath + "\r\n";       
    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.