When creating an xml file and writing a value I get the follwoing error:
'the requested operation cannot be performed on a file with a user-mapped section open. visual studio'
Looking around the internet there are many people getting this error. Obviously the file is not released for me to then open it and start writing records to it.
What can I do to make sure the file is released?
My Add record code
Public Function add_record_revision_number(ByVal strFile As String, strElement As String, strVersion As String, strFileName As String, strFilePath As String, strParentElement As String)
If clsFOLDER_FUNCTIONS.FileExists(strFilePath & "\" & strFileName & ".xml") = False Then
create_file(strFileName, strFilePath, strParentElement)
End If
Dim xmlDoc As XElement = XElement.Load(strFile)
xmlDoc.Add(New XElement(strElement, _
New XElement("version", strVersion) _
))
xmlDoc.Save(strFile)
xmlDoc = Nothing
Return 0
End Function
My Create File code
Public Function create_file(ByVal strFileName As String, ByVal strFilePath As String, ByVal strParentElement As String)
Dim empNM As XNamespace = "urn:lst-emp:emp"
Dim xDoc As New XDocument(New XDeclaration("1.0", "UTF-16", Nothing), New XElement(empNM + strParentElement))
Dim sw As New StringWriter()
Dim xWrite As XmlWriter = XmlWriter.Create(sw)
xDoc.Save(xWrite)
xWrite.Close()
' Save to Disk
xDoc.Save(strFilePath & "\" & strFileName & ".xml")
xDoc = Nothing
Return 0
End Function