• 0

Used by another prosses?


Question

this code:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        file = "options.xml"

        'Create a new stream representing the file we are reading from.
        stream = New StreamReader(file, True)

        'Create a new XmlTextWriter.
        xwriter = New XmlTextWriter(file, System.Text.Encoding.UTF8)

        'Write the beginning of the document including the 
        'document declaration. Standalone is true. 
        xwriter.WriteStartDocument(True)

        'Write the beginning of the "data" element. This is 
        'the opening tag to our data. 
        xwriter.WriteStartElement("options")

        'Get the first data element from the file.
        xwriter.WriteElementString("php", TextBox1.ToString)

        xwriter.WriteEndElement()  'End the "data" element.
        xwriter.WriteEndDocument() 'End the document

        'Flush the XML document to the underlying stream and
        'close the underlying stream. The data will not be written out 
        'to the stream until either the Flush() method is called or 
        'the Close() method is called.
        xwriter.Close()

    End Sub

always produses this error:

An unhandled exception of type 'System.IO.IOException' occurred in mscorlib.dll

Additional information: The process cannot access the file "F:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\NeoIP\bin\options.xml" because it is being used by another process.

Why?

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

Because you're opening the file for reading with a StreamReader, and then trying to open it for writing with a XmlTextWriter at the same time.

Link to comment
Share on other sites

  • 0

Maybe you meant to create a new FileStream (System.IO.FileStream) instead of a StreamReader, and use that to create the XmlTextWriter? :unsure:

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.