I am testing an app to read from a XML file (Working) and save to a XML file (NOT WORKING).
Here is my code that is not working. any ideas on how to fix this? I need to be able to save to the XML file. The error I am getting is: STREAM WAS NOT WRITEABLE
Code:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim strTime As String
strTime = Now.ToString
Dim _assembly As Assembly
_assembly = [Assembly].GetExecutingAssembly()
Dim FileName = _assembly.GetManifestResourceStream("EmbeddedResource.xml")
Try
Dim xmlData As New XmlDocument
Dim nodeRoot, nodeTroubleInfo, nodeDateTimeSaved As XmlNode
xmlData.Load(FileName)
nodeRoot = xmlData.SelectSingleNode("//DATA")
nodeTroubleInfo = nodeRoot.SelectSingleNode("//TroubleInfo")
nodeTroubleInfo.InnerText = txtNotes.Text
nodeDateTimeSaved = nodeRoot.SelectSingleNode("//DateTimeSaved")
nodeDateTimeSaved.InnerText = strTime
xmlData.Save(FileName)
MsgBox("SAVE Button Pressed!", MsgBoxStyle.Information, "Note saved successfully!")
Catch ex As Exception
MsgBox("Error saving note. The error was: " & vbCrLf & Err.Description, MsgBoxStyle.Exclamation, "Error saving information to file.")
Exit Sub
End Try
End Sub
It's not a file. It's part of the assembly. You cannot write to it.
The best you could do is read from the assembly and write to a separate XML file on disk. That file, you could read and write.