I am using following two code to load an XML.Some other process is updating the same XML while i am trying to Load it.It's giving me below error in both case:-
The process cannot access the file 'D:\Projects\WriteOnXml\Xml\test.xml' because it is being used by another process.
1)
using (FileStream xml = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
XDocument xdoc = XDocument.Load(xml);
}
2)
using (StreamReader sr = new StreamReader(dest))
{
xdoc = XDocument.Load(sr);
}
I want to load it while it is updating by some other process. Any better approach.