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.
Question
xxpor
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 Subalways produses this error:
Why?
Link to comment
Share on other sites
3 answers to this question
Recommended Posts