Question

I'm currently facing a following issue,

I use xml file to store information and once my application is started it pulls data from xml file and based on that dynamically constructs views. The problem is that users can update data in xml file within the application and save it. However as views are already loaded with all data, user now doesn't see new data until application is restarted (closed and started again).

I'm looking for a way to refresh data inside certain elements after xml file is updated, or make it so it constantly checks data in xml file every time.

I'm thinking some sort of method that does this on a "save" button click when users update xml.

Was it helpful?

Solution

It looks like you are going to want something like the FileSystemWatcher.Changed Event. You can hook up to the event when the application loads, and know when the file changes. This will allow you to catch changes made both internally (by your program) and externally (by a text editor or something like that).

When a file change is detected, simply load the new file and refresh the views with the new data. This part can be a little complicated depending on how the data is loaded into the views. This could also require detection of changes in the views when external changes have also been made. Probably best to prompt the user before reloading. This all depends on your use case and the expected use by the user.

Sauce: http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.changed.aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top