locked
Need Some Help With FileSystemWather OpenNETCF RRS feed

  • Question

  •  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

    Thursday, October 2, 2008 8:19 AM

Answers

  • Hi Snipera51 ,

    FileSystemWatcher is to watch for changes in a specified directory. You can watch for changes in files and subdirectories of the specified directory. The changes include creatation,modification,deletion.

     

    For OpennetCF problem, I suggest you post it on OpennetCF forum, where you can get better reply.

     

    Best regards,

    Guang-Ming Bian - MSFT

     

    Monday, October 6, 2008 2:00 AM

All replies

  • Hi Snipera51 ,

    FileSystemWatcher is to watch for changes in a specified directory. You can watch for changes in files and subdirectories of the specified directory. The changes include creatation,modification,deletion.

     

    For OpennetCF problem, I suggest you post it on OpennetCF forum, where you can get better reply.

     

    Best regards,

    Guang-Ming Bian - MSFT

     

    Monday, October 6, 2008 2:00 AM
  • I posted there also chris answered he is from the opennetcf staff and he said it works...but at me it doesent i made a simple app for desktop using fsw and it works just fine on mobiles same code but using the opennetcf fsw it doesnt work ...well it work it fires events only if i create a file dir using coding and it doest fire if i am creating from the mobile itself...I mail chris but he didnt msg me yet for not i am looking into shchangenotifyregister and make it in c++ but it would have been mutch easier in c# what is your mail?
    Tuesday, October 7, 2008 12:29 PM
  • Hi Snipera51,

    If you want to use native code to do it, please refer following thread:

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2666864&SiteID=1

     

    Best regards,

    Guang-Ming Bian - MSFT

    Wednesday, October 8, 2008 2:57 AM