We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

grid and xml.write

Thread ID:

Created:

Updated:

Platform:

Replies:

11027 Feb 20,2004 02:21 PM UTC Feb 20,2004 03:51 PM UTC WinForms 4
loading
Tags: GridControl
Administrator [Syncfusion]
Asked On February 20, 2004 02:21 PM UTC

Hi, I have an xml file that is read into a grid using xml.read. I want to changes made in the grid back to the same file but when I call xml.write with the path/name of that file it gives me an error saying it ''cannot access the file because it is being used in another process''. How can I get around this - and what process is the file being used in after the initial xml.read call? THanks CB

Administrator [Syncfusion]
Replied On February 20, 2004 02:53 PM UTC

I do not think the grid has anything to do with this. Are you closing the reader?

Administrator [Syncfusion]
Replied On February 20, 2004 03:03 PM UTC

Here is the code that opens/reads the xml file If nia_tx Is Nothing Then nia_tx = New DataSet nia_tx.ReadXmlSchema("nia_translation_exchange.xsd") Try ''ac changed to dialog box openFileDialog1.InitialDirectory = "c:\" openFileDialog1.Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*" openFileDialog1.FilterIndex = 2 openFileDialog1.RestoreDirectory = True If openFileDialog1.ShowDialog() = DialogResult.OK Then myStream = openFileDialog1.OpenFile() If Not (myStream Is Nothing) Then sFilename = openFileDialog1.FileName nia_tx.ReadXml(openFileDialog1.FileName) myStream.Close() End If End If Catch ex As Exception Dim _x As String = ex.ToString End Try End If And here is the code that attempts to save the file: '' Create the FileStream to write with. Dim myFileStream As New System.IO.FileStream _ (sFilename, System.IO.FileMode.Create) '' Create an XmlTextWriter with the fileStream. Dim myXmlWriter As New System.Xml.XmlTextWriter _ (myFileStream, System.Text.Encoding.Unicode) '' Write to the file with the WriteXml method. nia_tx.WriteXml(myXmlWriter) myXmlWriter.Close() The save works fine when I call a save file dialog box and opt to replace the current file. Is there some way to explicitly close the xml file? Thanks, CB >I do not think the grid has anything to do with this. > >Are you closing the reader?

Administrator [Syncfusion]
Replied On February 20, 2004 03:46 PM UTC

Hi Clay, Disgregard this question - I found the problem - THanks again! >Here is the code that opens/reads the xml file > >If nia_tx Is Nothing Then > nia_tx = New DataSet > nia_tx.ReadXmlSchema("nia_translation_exchange.xsd") > > Try > ''ac changed to dialog box > openFileDialog1.InitialDirectory = "c:\" > openFileDialog1.Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*" > openFileDialog1.FilterIndex = 2 > openFileDialog1.RestoreDirectory = True > > If openFileDialog1.ShowDialog() = DialogResult.OK Then > myStream = openFileDialog1.OpenFile() > If Not (myStream Is Nothing) Then > sFilename = openFileDialog1.FileName > nia_tx.ReadXml(openFileDialog1.FileName) > myStream.Close() > End If > End If > > Catch ex As Exception > Dim _x As String = ex.ToString > End Try > End If > >And here is the code that attempts to save the file: > > '' Create the FileStream to write with. > Dim myFileStream As New System.IO.FileStream _ > (sFilename, System.IO.FileMode.Create) > '' Create an XmlTextWriter with the fileStream. > Dim myXmlWriter As New System.Xml.XmlTextWriter _ > (myFileStream, System.Text.Encoding.Unicode) > '' Write to the file with the WriteXml method. > nia_tx.WriteXml(myXmlWriter) > myXmlWriter.Close() > >The save works fine when I call a save file dialog box and opt to replace the current file. Is there some way to explicitly close the xml file? > >Thanks, >CB > >>I do not think the grid has anything to do with this. >> >>Are you closing the reader?

Administrator [Syncfusion]
Replied On February 20, 2004 03:51 PM UTC

Is openFileDialog1 a class member? If so, it is still probably around holding onto the file you want to replace. I would make it a local variable and see if it going out of scope will release the file.

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;