jlucben
Pro
Posts: 27
Joined: Wed Oct 12, 2016 1:54 pm

Load user settings not working in UWP

Fri Oct 28, 2016 6:59 pm

Hi

I save user settings as is :

var file = await folder.CreateFileAsync(nomsave , CreationCollisionOption.ReplaceExisting);
var stream = await file.OpenAsync(FileAccessMode.ReadWrite);
userSettingsDoc.Save(stream.AsStreamForWrite());
stream.Dispose();

Where
folder = ApplicationData.Current.LocalFolder;
nomsave = nomuser + "-Settings.siml";
private string nomuser = "Jean luc";
and my Bot : botUser = simlBot.CreateUser(nomuser);

When I change botUser Settings during bot session , i retrieve the changed values in the saved file.

But I cannot reload the settings - Here is the code I Used :

var file = await folder.GetFileAsync(nomsave);
var stream = await file.OpenReadAsync();
Stream streambis = stream.AsStreamForRead();
XDocument.Load(streambis);

And the changed value of the saved file are not retrieved

Thanks for your help

Regards

Jean-Luc







ButI cannot reload

jlucben
Pro
Posts: 27
Joined: Wed Oct 12, 2016 1:54 pm

Re: Load user settings not working in UWP

Fri Oct 28, 2016 7:34 pm

I Try also

string filenewpath = folder.Path + "/" + nomsave;
XDocument.Load(filenewpath);

the value of filenewpath is OK
but the result is the same - not correct

regards

JeffersonStack
Pro
Posts: 44
Joined: Fri Apr 05, 2013 1:20 am

Re: Load user settings not working in UWP

Fri Oct 28, 2016 8:10 pm

Check if after XDocument.Load(filenewpath), XDocument has some XML content it. If so, does the root element name is <UserSettings>?

jlucben
Pro
Posts: 27
Joined: Wed Oct 12, 2016 1:54 pm

Re: Load user settings not working in UWP

Fri Oct 28, 2016 8:42 pm

Hello

When I display in resultat.text
var xdoc =XDocument.Load(filenewpath);
Resultat.Text = xdoc.FirstNode.ToString();


<Siml>
<UserSettings>
<Variable Name="Name" Value="Jean luc" />
<Variable Name="Test" Value="Test Chargement" />
</UserSettings>
</Siml>

But after :
Resultat.Text = botUser.Settings["Name"].Value;

give exception Une exception de type 'System.ArgumentNullException' s'est produite dans mscorlib.ni.dll mais n'a pas été gérée dans le code utilisateur
{"Value cannot be null."}

Thanks for your help

jlucben
Pro
Posts: 27
Joined: Wed Oct 12, 2016 1:54 pm

Re: Load user settings not working in UWP

Sat Oct 29, 2016 6:55 pm

Hello after some tries :

This code is working

string filenewpath = folder.Path + "/" + nomsave;
Resultat.Text = filenewpath;
var xdoc = XElement.Load(filenewpath).Element("UserSettings");
botUser.Settings.Load(xdoc);
Resultat.Text = botUser.Settings["Name"].Value;

And this one isn't working

string filenewpath = folder.Path + "/" + nomsave;
Resultat.Text = filenewpath;
var xdoc =XDocument.Load(filenewpath);
botUser.Settings.Load(xdoc);
Resultat.Text = botUser.Settings["Name"].Value;

Regards

Jean-Luc

User avatar
Leslie
Lead Software Architect
Posts: 353
Joined: Fri Sep 14, 2012 12:20 pm
Contact: Website

Re: Load user settings not working in UWP

Sat Oct 29, 2016 10:11 pm

Thank you jlucben for taking the time to post your solution, the first code works because the method Load() is expecting the root element to be<UserSettings> instead of <Siml>.

This actually calls in for some improvements and from next version onwards the Load() method in all classes that have the GetDocument() method will also accept <Siml> as the root element.

Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 1 guest