XMLTextReader

Hi,

I am trying to use the XMLTextReader's Read(), I get an exception always, saying that file is being used by another process.. I know not where is that being used..

Any thoughts...




Answer this question

XMLTextReader

  • bluemoon2181

    Hi Frederik,

    Thanks for the reply, XmlDocument is not so handy to use as XmlTextReader, here there are many properties available to check conditions and get details.. Its hard to trace in XmlDocument class.. Any best pointers can help me..

    Using XmlTextReader is it possible to get the total rowcount/ element count present in Xml file



  • Marc A1

    Ok if giving the control(s) the xml as a string isnt good enough, how about you minimize the open time of the file Why dont you load the xml into a memory stream or string and shut the file (ie use a using statement), then load it into your reader (all within your control). I would make the control try to open it again (ie in a loop for x tries) if it fails to cover any timing issues with the file lock.




  • wayne62682

    Cant you just load it once and pass it in to each control Maybe load the xml file into a string then pass the string in to each control where you load it into a reader.

    Use something like this to load it from the string.

    XmlTextReader objReader=new XmlTextReader(new StringReader(sXML));



  • andokai

    Hi Frederick,

    I am getting the same exception (Used by another process) when writing xml.. I know not why...

    Any Ideas...



  • HJ Liu

    If you use an XmlDocument, you can also edit the contents, and save it back easily.

  • SanXu

    Hello,

    I just figured it out.. I am using 3 controls to display the same file in different formats... Now I was trying to load in 2 controls and therefore I got this exception..

    Anyway I need to load the same in the 3 controls...

    Any techniques..



  • bhav2007

    Hello,

    Thank you all for the responses, I will try and let you know..



  • flyte

    Maybe this works:
    Create a FileStream for the XML file that you want to read. Use the 4 argument constructor of FileStream; the one that lets you allow the FileShare parameter, and set this parameter to FileShare.Read.

    FileStream fs = new FileStream (@"c:\directory\myxmlfile.xml", FileMode.Open, FileAccess.Read, FileShare.Read);

    Then, you can use this FileStream as an argument in the constructor of the xml reader:

    XmlTextReader myReader = new XmlTextReader (fs);





  • JohnCR

    Hi,

    Sorry, the dealings are basic, to be a massive implementation...



  • Magnus Green

    I do not exactly understand what you're meaning

    Do you only need to display different values from this xml file in some controls
    Then, it is absoletly not necessary to use 3 xmlreaders to read this xml file. You can also work with XmlDocument and Xpath to retrieve the values.

    However, I do not know what you precisely want.


  • jeremy7768

    Hi friends,

    The root cause of the problem mentioned above was with one of the custom control that does not allow to share by default, setting it allows me to pass the same file name to three of the controls.

    Thanks again!! for all your thoughts..

    But some queries posted above remains..

    Thanks for the reply, XmlDocument is not as handy as XmlTextReader, in XmlTextReader there are many properties available to check conditions and get details.. Its hard to trace in XmlDocument class.. Any best pointers can help me.. Basically need to know more abt XmlDocument.

    Using XmlTextReader and/or XmlDocument is it possible to get the total rowcount of element and text count present in Xml file In other words I need to know the total elements and text present..

    Glad to see any info on this..



  • rodgerpb

    Thats lovely Frederick..

    I am not sure if I will be in trouble again.. For 1 control I have to use the filename, other I am parsing so fs will do.. yet for another I do not know how the design will be..

    Is there an easy deal to syncronize, so that I will be able to see the changes..



  • iJatin

    hi,

    i guess the time had come to show up some code to see whats wrong

    best regards



  • Devinder Singh

    Hello,

    Would you like to use same connection object for XML file

    When 1st control has done with connection object than use connection for 2nd control etc.

    If you want to use it in same time. Use threads.. I hope my words are helpful to you.

    Happy coding...


  • XMLTextReader