views:

179

answers:

2

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

A: 

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

Timores
Yeah, it returns Nothing. Also UserConfigDataSource (which is an XMLProvider object) Source.LocalPath property returns the exception. It just doesn't like the fact that I am calling something relative to the install path I am guessing.Cory
OffApps Cory
Just saw this post: http://stackoverflow.com/questions/1059916/using-relative-uri-as-xmldataproviders-source . Will check it out tomorrow or Monday.Cory
OffApps Cory
A: 

Used the suggestion HERE

FileInfo file = new FileInfo("configuration.xml"); provider.Source = new System.Uri(file.FullName);

All worked well.

Cory

OffApps Cory