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