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_Changed(object sender, XObjectChangeEventArgs e)
{
//what is the code needed here..?
}
Rather than subscribing to
Changed, you should subscribe toChangingso 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?