Question some Help with FileSystemWatcher Class

Last post 10-15-2008 21:50 by ctacke. 7 replies.
Page 1 of 1 (8 items)
Sort Posts: Previous Next
  • 10-01-2008 15:48

    Question some Help with FileSystemWatcher Class

     Hi all....i am trying to make an mobile application that will monitor all changes done by all processes on the mobile witch involves Creating Renaming Deleteing Changeing of a file or a directory. Let's restrict it to myDocument for example and i want to know When a file is modified creaded deleted in any way...

     I saw the sample Example that uses The FileSystemWatcher And it monitor File Creation and so one ...only when the file is created by me from myApp ....what i want is to be able to monitor files that i create from any process in the directory(myDocuments) that is monitored by the file system wather...

     

    Here is the part them the code that needs your attention and help...

     

     namespace XmlParser
    {
        public class My_Monitor
        {
           
            
            public My_Monitor() {

                string root_myDocuments;
                root_myDocuments = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
                
                FileSystemWatcher File_Monitor = new FileSystemWatcher(root_myDocuments,"*.*");
                
                File_Monitor.IncludeSubdirectories = true;
                File_Monitor.NotifyFilter = NotifyFilters.CreationTime | NotifyFilters.DirectoryName | NotifyFilters.FileName | NotifyFilters.CreationTime | NotifyFilters.Size | NotifyFilters.LastAccess;
                File_Monitor.EnableRaisingEvents = true;

                File_Monitor.Created += new FileSystemEventHandler(File_Monitor_Created);
                File_Monitor.Changed += new FileSystemEventHandler(File_Monitor_Changed);
                File_Monitor.Deleted += new FileSystemEventHandler(File_Monitor_Deleted);
                File_Monitor.Renamed += new RenamedEventHandler(File_Monitor_Renamed);
                
                
                
                
            }

            void File_Monitor_Renamed(object sender, RenamedEventArgs e)
            {
                MessageBox.Show("File Renamed");
            }

            void File_Monitor_Deleted(object sender, FileSystemEventArgs e)
            {
            
                MessageBox.Show("File Deleted");
            }

            void File_Monitor_Changed(object sender, FileSystemEventArgs e)
            {
                MessageBox.Show("File Changed");
            }

            void File_Monitor_Created(object sender, FileSystemEventArgs e)
            {
                MessageBox.Show("File Created");
                
            }    
        }
    }

     

     

     

    namespace xmlprser
    {
        public partial class MobileSync : Form
        {
            public MobileSync()
            {
                InitializeComponent();
                My_Monitor S_Monitor = new My_Monitor();
            } 

            private void button1_Click(object sender, EventArgs e)
          {
               
     
                this.label1.Text = "intra";
           
                System.IO.StreamWriter sw = System.IO.File.CreateText("\\My Documents\\test.txt");
                sw.WriteLine("Test");
                sw.Flush();
                sw.Close();
           

                Create_XmlTemplate xml = new Create_XmlTemplate();
                         
     
           }
          
            private void quit_b_Click(object sender, EventArgs e)
            {
               Application.Exit();
            }

            private void button2_Click_1(object sender, EventArgs e)
            {
                DirectoryInfo dw = new DirectoryInfo("\\My Documents\\MADe_now");
                if (dw.Exists)
                {
                    MessageBox.Show("Dir Already exists");
                   
                }
                else
                {
                    dw.Create();
                    MessageBox.Show("Dir Created");
                }
            }
           
        }
    }

     

    I dont want to create the files and directors from myapp so i can get an eventhandler get's trigered.Like it is working now.

     

    I want after i start my app and browse for example to the My Documents if  i make a dir to be notified by my app that a file was created in the dir that i am monitoring...

     

     

    I hope i was clear about it. Can anybody help me with this ? is it possible using FileSystemWatcher(can it be used the way i want it).How does FileSystemWather works ? i thought i got it but now i am confused.

     Something like this Using only c# is what i want my app to do

    http://msdn.microsoft.com/en-us/library/bb158663.aspx

     

    Thanks in advance...Raz

     

     

     

  • 10-02-2008 5:16 In reply to

    Re: Question some Help with FileSystemWatcher Class

     Shall i understand that this only works when creating files from with the Windows CE OS itself not if i am creating files from within the device or using ActivSync or other remote?

    Thanks

  • 10-02-2008 11:08 In reply to

    • ctacke
    • OpenNETCF Staff
    • Top 10 Contributor
    • Joined on 07-27-2007
    • Indiana
    • Posts 1,939

    Re: Question some Help with FileSystemWatcher Class

     I just verified that the FSW does indeed fire events properly just fine, regardless of how the file was created.  One of the tests I ran can be seen here. I don't see anything obviously wrong with your code.  What type of device is this running on?

  • 10-02-2008 15:35 In reply to

    Re: Question some Help with FileSystemWatcher Class

    this is run on windows mobile 6 professional device! I will test what u did and tell u how it goes? On what does FSW work?
  • 10-02-2008 16:01 In reply to

    Re: Question some Help with FileSystemWatcher Class

     I havent tested but i saw that u create a file and delete it:) and the events are trigged in my case also if i create a file and delete...But if i dont a add a function to create a file and want to create it after i run the app going in the dir that is watcher and create a file it won't triggered...And would like it to trigger...This is my basic question...

     

    Thanks a lot for your answer and help

  • 10-08-2008 19:02 In reply to

    Re: Question some Help with FileSystemWatcher Class

    ctacke hi. I mailed u with a simple app to check it out and tell me if i do something wrong.U got my mail? Thanks keep up the good work
  • 10-15-2008 19:30 In reply to

    Re: Question some Help with FileSystemWatcher Class

    ok 10x
  • 10-15-2008 21:50 In reply to

    • ctacke
    • OpenNETCF Staff
    • Top 10 Contributor
    • Joined on 07-27-2007
    • Indiana
    • Posts 1,939

    Re: Question some Help with FileSystemWatcher Class

    We've had an extremely heavy schedule for the past 2 weeks and haven't had the time to check your specific project.  Again, we've tested that the FSW does indeed work as expected under our test environement, but we do intend to run your test and verify that it works for us.

Page 1 of 1 (8 items)