Web Images News Groups Books Scholar Gmail more »
Recently Visited Groups | Help | Sign in
Google Groups Home
FileSystemWatcher and events
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
bcm  
View profile  
 More options Mar 10 2002, 1:43 am
Newsgroups: microsoft.public.dotnet.framework, microsoft.public.dotnet.framework.windowsforms, microsoft.public.dotnet.general, microsoft.public.dotnet.languages.csharp, microsoft.public.in.dotnet.framework, microsoft.public.vsnet.general
From: "bcm" <b...@nc.rr.com>
Date: Sat, 9 Mar 2002 12:41:59 -0500
Local: Sun, Mar 10 2002 1:41 am
Subject: FileSystemWatcher and events
In the MSDN documentation, a console application is provided in the
FileSystemWatcher article (just search for FileSystemWatcher Class). I am
attempting to reproduce essentially the same thing with a Windows form, and
I am utterly baffled. I believe it's because I don't fully understand the
raising and handling of events. Specifically, the author provides the
following lines within the Main() method ("watcher" is the
FileSystemWatcher):

        // Add event handlers.
        watcher.Changed += new FileSystemEventHandler(OnChanged);
        watcher.Created += new FileSystemEventHandler(OnChanged);
        watcher.Deleted += new FileSystemEventHandler(OnChanged);
        watcher.Renamed += new RenamedEventHandler(OnRenamed);

Where would these go in a WinForms app?

Also, these lines are provided, and my question is the same: where in my
WinForm code do they need to be placed?:

    // Define the event handlers.
    public static void OnChanged(object source, FileSystemEventArgs e)
    {
        // Specify what is done when a file is changed, created, or deleted.
       Console.WriteLine("File: " +  e.FullPath + " " + e.ChangeType);
    }

I feel like I've exhausted every possible scenario, but I must not have. I'm
simply trying to have a textBox report when a file has been added to a
particular directory.

I don't expect anybody to actually READ all this, but just in case they
might here is my (useless) code as it stands:

using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

using System.Data;

using System.IO;

using System.Diagnostics;

namespace FileSystemWatcher

{

/// <summary>

/// Summary description for Form1.

/// </summary>

public class Form1 : System.Windows.Forms.Form

{

private System.Windows.Forms.TextBox textBox1;

private System.IO.FileSystemWatcher fsw;

private System.Windows.Forms.Button button1;

/// <summary>

/// Required designer variable.

/// </summary>

private System.ComponentModel.Container components = null;

public Form1()

{

//

// Required for Windows Form Designer support

//

InitializeComponent();

//

// TODO: Add any constructor code after InitializeComponent call

//

fsw.Path = @"C:\Testing";

fsw.NotifyFilter = NotifyFilters.CreationTime;

}

/// <summary>

/// Clean up any resources being used.

/// </summary>

protected override void Dispose( bool disposing )

{

if( disposing )

{

if (components != null)

{

components.Dispose();

}
}

base.Dispose( disposing );

}

#region Windows Form Designer generated code

/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

this.textBox1 = new System.Windows.Forms.TextBox();

this.fsw = new System.IO.FileSystemWatcher();

this.button1 = new System.Windows.Forms.Button();

((System.ComponentModel.ISupportInitialize)(this.fsw)).BeginInit();

this.SuspendLayout();

//

// textBox1

//

this.textBox1.Location = new System.Drawing.Point(8, 48);

this.textBox1.Name = "textBox1";

this.textBox1.Size = new System.Drawing.Size(272, 20);

this.textBox1.TabIndex = 0;

this.textBox1.Text = "textBox1";

//

// fsw

//

this.fsw.EnableRaisingEvents = true;

this.fsw.SynchronizingObject = this;

this.fsw.Changed += new System.IO.FileSystemEventHandler(this.fsw_Changed);

this.fsw.Created += new System.IO.FileSystemEventHandler(OnChanged);

//

// button1

//

this.button1.Location = new System.Drawing.Point(208, 208);

this.button1.Name = "button1";

this.button1.TabIndex = 1;

this.button1.Text = "button1";

this.button1.Click += new System.EventHandler(this.button1_Click);

//

// Form1

//

this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);

this.ClientSize = new System.Drawing.Size(292, 266);

this.Controls.AddRange(new System.Windows.Forms.Control[] {

this.button1,

this.textBox1});

this.Name = "Form1";

this.Text = "Form1";

((System.ComponentModel.ISupportInitialize)(this.fsw)).EndInit();

this.ResumeLayout(false);

}

#endregion

/// <summary>

/// The main entry point for the application.

/// </summary>

[STAThread]

static void Main()

{

Application.Run(new Form1());

}

private void fsw_Changed(object sender, System.IO.FileSystemEventArgs e)

{

textBox1.Text = "Directory Changed";

}

public void OnChanged(object source, FileSystemEventArgs e)

{

// Specify what is done when a file is changed, created, or deleted.

textBox1.Text = "Directory Changed";


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bipin  
View profile  
 More options Mar 11 2002, 11:11 pm
Newsgroups: microsoft.public.dotnet.framework, microsoft.public.dotnet.framework.windowsforms, microsoft.public.dotnet.general, microsoft.public.dotnet.languages.csharp, microsoft.public.in.dotnet.framework, microsoft.public.vsnet.general
From: "Bipin" <bipinjo...@hotmail.com>
Date: Mon, 11 Mar 2002 20:39:59 +0530
Local: Mon, Mar 11 2002 11:09 pm
Subject: Re: FileSystemWatcher and events
Hi,
My article on the topic at www.bipinjoshi.com may help.

http://www.bipinjoshi.com/articles/usingfilesystemwatcher.asp?id=30

--
Thanks.
Bipin Joshi
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Software Developer | Author
.Net Simplified @ Bipin Joshi.com
www.bipinjoshi.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

System.IO.FileSystemEventHandler(this.fsw_Changed);


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google