OpenNETCF FileSystemWatcher wont fire events

M

Matthew lOck

Hi, I am trying to use the OpenNETCF FileSystemWatcher to watch for a
file changed or created event but it will not fire any events. I have
messed around with the directory, file extension filter, notify filter
without any luck. I am using Windows Mobile 5 (HP HX2750), and .NET CF
2.0. Has anyone got this to work on WM5? Does it require the latest
version of the OpenNETCF (Version 2.0 - $50), or is it possible for the
free 1.4 version to work?

My Code is:

OpenNETCF.IO.FileSystemWatcher watcher = new
OpenNETCF.IO.FileSystemWatcher(@"\", "");

watcher.EnableRaisingEvents = false;

watcher.NotifyFilter = OpenNETCF.IO.NotifyFilters.FileName |
OpenNETCF.IO.NotifyFilters.LastWrite | OpenNETCF.IO.NotifyFilters.Size
| OpenNETCF.IO.NotifyFilters.CreationTime;

watcher.Changed += new
OpenNETCF.IO.FileSystemEventHandler(watcher_Changed);

watcher.Created += new
OpenNETCF.IO.FileSystemEventHandler(watcher_Created);

watcher.Renamed += new
OpenNETCF.IO.RenamedEventHandler(watcher_Renamed);

watcher.EnableRaisingEvents = true;



Thanks in advance.
Matthew
 
P

Peter Foot [MVP]

For a start you haven't specified a file type filter - use this instead:-
OpenNETCF.IO.FileSystemWatcher watcher = new
OpenNETCF.IO.FileSystemWatcher(@"\", "*.*");

There was a bug with one of the event types not working in SDF v1.x which I
fixed in the v2.0 code. Also you can use the v2.0 binary only version for
free, it doesn't have the visual studio tools and help integration like the
$50 version. But because v1.4 was built to work with NETCF v1.0 it's not
optimised for v2.0, so I'd recommend using SDF 2.0 within a .NETCF v2.0
project.

Peter
 
G

Guest

It looks like the events are not raised for the root "\". You can use any
other directory.
 
M

Matthew Lock

Thanks for they great feedback guys, unfortunately I have found that
the problem is caused by the directory path being incorrect, it appears
to be case sensitive. I am getting the path using the following method.

public static string FileLocation(string file)
{

return
Path.Combine(Path.GetDirectoryName(Assembly.GetCallingAssembly().GetName().CodeBase),
file).TrimStart("file:\\".ToCharArray());

}



The TrimStart is just to make it compatable with the desktop .NET
framework.

Do you have any ideas on how to get this to return the path with the
correct case for the directory name? For example it returns '\Program
Files\MyApp' yet it should return '\Program Files\myapp'. Hard coding
this method is unfortunately not an option for this application.

Btw you are right about the root not raising events, I was just using
it as an example, however it is handy to know. The 1.4 version is
working well for me, I am only using it in a simple scenario, I tried
the 2.0 version and they behave the same (for my usage anyway) after
some minor code changes pointed out in the OpenNETCF forum -
http://www.opennetcf.org/forums/post.asp?method=TopicQuote&TOPIC_ID=5391&FORUM_ID=17.

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top