将用户配置数据保存到 XML 和相对 URI 错误
晚上好,
我正在开发一个程序,其中一些应用程序配置信息存储在 Userconfig.xml 文件中。我通过相对 URI 将文件作为 XAML 中的 XMLDataProvider 加载:
<XmlDataProvider x:Name="UserConfigDataSource" x:Key="UserConfigDataSource" Source="UserConfig.xml" d:IsDataSource="True"/>
我有许多项目始终绑定到文档中的元素以及保存到 XMLDataProvider 的事件处理程序:
Private Sub SaveConfig(ByVal sender as Object, ByVal e as System.EventArgs)
'TODO: Add event handler implementation here
Dim SavePath As String = UserConfigDataSource.Source.LocalPath.ToString
Dim XMLDoc = UserConfigDataSource.Document
UserConfigDataSource.Document.Save(SavePath)
End Sub
当执行此操作时,我收到错误“此操作不是支持相对 URI”。有没有一种好方法来生成绝对 URI(除了获取程序集执行位置并从末尾修剪可执行文件名之外)?我预计这是一个稍微简单的过程。任何帮助将不胜感激。
科里
Good evening,
I am working on a program where some application config info is stored in a Userconfig.xml file. I am loading the file as an XMLDataProvider in the XAML via relative URI:
<XmlDataProvider x:Name="UserConfigDataSource" x:Key="UserConfigDataSource" Source="UserConfig.xml" d:IsDataSource="True"/>
I have a number of items throughout bound to elements in the document and an event handler that saves to the XMLDataProvider:
Private Sub SaveConfig(ByVal sender as Object, ByVal e as System.EventArgs)
'TODO: Add event handler implementation here
Dim SavePath As String = UserConfigDataSource.Source.LocalPath.ToString
Dim XMLDoc = UserConfigDataSource.Document
UserConfigDataSource.Document.Save(SavePath)
End Sub
When this executes I get the error "This operation is not supported for a relative URI". Is there a good way to produce an absolute URI (aside from getting the assembly executing location and trimming the executable filename from the end)? I expected this to be a somewhat simple procedure. Any help would be greatly appreciated.
Cory
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否查看过调试器中 SavePath 的确切值?由于它是 XAML 中的 URI,因此 XmlDocument.Save 可能无法理解它的语法。
您也可以尝试 AbsoluteUri.ToString
Have you looked at the exact value of SavePath in the debugger ? As it was a URI in XAML, it may have a syntax not understood by XmlDocument.Save.
You could also try AbsoluteUri.ToString
使用了此处的建议,
一切顺利。
科里
Used the suggestion HERE
All worked well.
Cory