Click to See Complete Forum and Search --> : XPathDocument Constructor


George2
May 15th, 2008, 12:57 AM
Hello everyone,


When use the following XPathDocument Constructor, we can not open the XML file in exclusive mode. Any ideas about how to open an XML file in exclusive mode and using XPath Query?

http://msdn.microsoft.com/en-us/library/te0h7f95(VS.80).aspx


thanks in advance,
George

Arjay
May 15th, 2008, 03:02 AM
The link you provided points to the constructor that takes a string parameter to the file path.

Now without giving you the answer directly, I ask you to determine if there are other XPathDocument constructors that you can use that will enable you to open a file with an exclusive lock and use one of these other constructors.

George2
May 15th, 2008, 03:06 AM
Thanks for your hint, Arjay!


I have written some code, could you review whether it is correct solution please? :-)


FileStream fs = new FileStream("foo.txt", FileMode.Open, FileAccess.Read, FileShare.None);
XPathDocument xp = new XPathDocument(fs);


The link you provided points to the constructor that takes a string parameter to the file path.

Now without giving you the answer directly, I ask you to determine if there are other XPathDocument constructors that you can use that will enable you to open a file with an exclusive lock and use one of these other constructors.


regards,
George

Arjay
May 15th, 2008, 03:20 AM
Thanks for your hint, Arjay!


I have written some code, could you review whether it is correct solution please? :-)


FileStream fs = new FileStream("foo.txt", FileMode.Open, FileAccess.Read, FileShare.None);
XPathDocument xp = new XPathDocument(fs);





regards,
GeorgeC'mon George, don't ask for this. Test the code yourself. (Hint: use the forum when you've exhausted all the other options).