Click here to Skip to main content
15,846,727 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi guys

I have a Silverlight 4 (c#) app where I need to do some simple file mangement (list files and folders, open files, navigate on folder tree, etc.).
Right now I'm gathering the necessary partial solutions and pieces of reusable code to build the full thing.

These files and folders are online resources and will be MS Word, MS Excel, MS Powerpoint and PDF documents.

So far I've been able to read the folder tree, each folder content and dispay it.
I've also been able to open each file using the correct application and to find out if, at a given moment, a file is opened by someone.

Now comes the problem!

Let's supose that a user A opens a file (let's say, an excel workbook) for editing.
When a user B tries to open that same file he gets a "file in use" message box with the user A identification and an option for notification wher User A releases the file.

When that notificaton callback reaches user B he gets the "File now available" message box and an option to reopen the file with read/write previleges.

I'm able to find out if the file is still opened and can create a timer event to check on the avalability of that file from time to time (for instance, every 15 seconds).

But what I realy wanted to do is to hook on that callback event that user B got and notify also the silverlight app so I can do some processing on that same file.

Does anyone have a solution, or even a clue, on how to catch that event after a user has closed the file?

Thanks for all the help I can get.
Updated 5-Nov-11 6:20am
Amir Mahfoozi 6-Nov-11 7:43am    
"But what I realy wanted to do is to hook on that callback event that user B got and notify also the silverlight app so I can do some processing on that same file."
You mean that you want to notify client side when the file is released ?
Jorge J. Martins 7-Nov-11 6:11am    
Yes but it has to be done in two steps.
The events on the files are managed on a Service (this is what I'm working on). Then the service notifies the clients (no problems here).

1 solution

Hope, you are using Silverlight OOB(Out Of Browser) mode for all file handling operation becaz normal mode won't allow.

Regarding file manipulation events, you don't need to write your own event handler. In stead, you can use FileSystemWatcher class of System.IO namespace with the below built-in event handlers.
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = filePath;
watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
   | NotifyFilters.FileName | NotifyFilters.DirectoryName;
// Only watch text files.
watcher.Filter = "*.txt";

// Add event handlers.
watcher.Changed += new FileSystemEventHandler(OnChanged);
watcher.Created += new FileSystemEventHandler(OnChanged);
watcher.Deleted += new FileSystemEventHandler(OnChanged);
watcher.Renamed += new RenamedEventHandler(OnRenamed);
Share this answer
Jorge J. Martins 7-Nov-11 6:04am    
Thanks for info.
Does the Changed event is raised on the following cases?
- user opens the file (I don't realy need this one);
- user closes the file without any changes;
- user saves the file without closing it.

If the answer is No, No, Yes then it doesn't suit the needs.
What I realy need is the Closed event! :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900