【发布时间】:2014-02-19 14:02:20
【问题描述】:
我正在测试一个应用程序以读取 XML 文件(工作)并保存到 XML 文件(不工作)。
这是我的代码不起作用。有想法该怎么解决这个吗?我需要能够保存到 XML 文件。我得到的错误是:STREAM WAS NOT WRITEABLE
代码:
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
【问题讨论】:
标签: xml vb.net winforms embedded-resource