I have a WPF application which is to be installed on a user's PC. Everything works great on my DEV PC (of course), but there are issues with the target PC. Specifically, the XML Settings file is not updatable if the application is installed under the Program Files folder, and the settings file is in the app directory (Windows 7).
I solved the issue by putting the settings file in C:\AppData\Company\Product folder. The Setup project properly createds this folder on the target PC and installs the Settings file there. This requires me, in development, to always manually
copy my Settings file to that folder so the installed app can find it. There is a property to copy a file to the output folder if needed, but I can't find one to copy to another folder. I solved the problem with the following code in my MainWindow_Initialized
event:
'Setup XML settings document. Dim dp As XmlDataProvider = Me.TryFindResource("MySettings") If dp IsNot Nothing Then _settings_path = dp.Source.LocalPath 'AppData location of settings file. 'If running from IDE, copy XML settings document to AppData folder. If Debugger.IsAttached Then Dim appPath As String = Path.GetDirectoryName(Reflection.Assembly.GetExecutingAssembly().Location) Dim sourcePath As String = My.Computer.FileSystem.GetParentPath(My.Computer.FileSystem.GetParentPath(appPath)) & "\" & Path.GetFileName(_settings_path) My.Computer.FileSystem.CopyFile(sourcePath, _settings_path, True) dp.Refresh End If settingsDoc = dp.Document settingsText = settingsDoc.OuterXml 'To compare later for changes made to XML document.
Also, I have similar code in the MainWindow_Closing event to copy the live file back to my project folder after saving it. Now, if I need to make manual changes to the XML file during development, I can do so in the IDE, and it is properly copied the proper folder before being loaded in my code.
So here's the issue: When I execute the dp.Refresh command, I get several debug messages in the output window:
problem with value index 0 problem with value index 0 problem with value index 1 problem with value index 1 problem with value index 2 problem with value index 2 problem with value index 3 problem with value index 3 problem with value index 0 problem with value index 0 problem with value index 0
These don't cause any real issues, but I'm curious why they are there, and if there is any way to remove them. I do need to do the refresh, because if I change my XML file in the IDE, the "real" XML file won't be aware of those changes, even though I copy the new file to the "real" location.
Any ideas? Thanks...
Ron Mittelman