I Want to raise an event to prevent any modification on the Xml file.
Simply raising an event is enough ? like
XElement doc = XElement.Load(@"d:\XMLFiles\namespace.xml");
doc.Changed +=new EventHandler<XObjectChangeEventArgs>(doc_Changed);
What is the code do i need to write inside doc_changed(..,...)
to rollback any modifications?
static void doc_Chang开发者_如何学编程ed(object sender, XObjectChangeEventArgs e)
{
//what is the code needed here..?
}
Rather than subscribing to Changed
, you should subscribe to Changing
so that you get notified before it happens.
The easiest way to prevent the change is to throw an exception... but that's quite a severe way of handling it. What situation are you really trying to prevent? Accidental changes due to a developer not understanding that this document is meant to be read-only?
精彩评论