I know something similar has already been asked, but here's my problem.
In a MDI WinForm I want to save each child window position and state, per application user, that is different by the logged in Windows user. My application has its own users; so I won't use the user settings like my.Settings... etc.
One option is to read/write directly to the database, but I don't like the idea to access the database for something so trivial as the windows positions. The plus is that I could store that information independently by the machine where the user works, wherever she logs in, her preferences will be remembered.
Another option, that I'd like to follow, is to use Xml to store that information in a file locally on the user's computer. The structure could be something like:
<form name="form name">
<Top>120</Top>
<Left>100</Left>
<State>0</State>
</form>
<form name="another form">
<Top>120</Top>
<Left>120</Left>
<State>1</State>
</form>
I'm having a hard time to understand how this could be done; maybe using Linq to Xml? I've found I can write something as simple as
Dim formPos As XElement = _
<User><%= My.Application.connectedUser.id %>
<form1>
<Top>120</Top>
<Left>100</Left>
<State>0</State>
</form1>
<form2>
<Top>120</Top>
<Left>100</Left>
<State>0</State>
</form2>
</User>
But:
1) How to dinamically fill the xml options: I want
<User id="1">
and not
<User><%= My.Application.connectedUser.id %>
that translates to <User>1
2) How to write the XElement when finished building it. Should I use an XmlWriter.Create
? Hot to pass it the XElement?
3) What happens when in the Xml file there's already a node with the same name, I want to overwrite the previous user settings if they are already there, but not append to the file, nor rewrite the entire file, of course
Thanks.