First of all I am an idiot who cant format questions appearantly so im gonna have to post this all in one codeblock. I have settings in my program that are programmatically added. These are added like this:
SettingsProperty SP = new SettingsProperty("LibImage" + AmountOfImages);
SP.PropertyType = typeof(string);
SP.DefaultValue = "goat";
SP.Provider = Settings.Default.Providers["LocalFileSettingsProvider"];
SP.Attributes.Add(typeof(UserScopedSettingAttribute), new UserScopedSettingAttribute());
Settings.Default.Properties.Add(SP);
Settings.Default.Reload();
Settings.Default.Save();
Settings.Default["LibImage" + AmountOfImages] = OFD.FileName;
MessageBox.Show(Settings.Default["LibImage" + AmountOfImages].ToString());
These get added to user.config and show up like this:
<setting name="LibImage1" serializeAs="String">
<value>C:\Users\User\Background\Biggie.jpg</value>
</setting>
<setting name="LibImage2" serializeAs="String">
<value>C:\Users\User\Background\BUSTA-RHYMES.jpg</value>
</setting>
When I restart the program I want to add all these images added to a panel like this:
int i = 0;
Settings.Default.Reload();
foreach (SettingsProperty P in Settings.Default.Properties)
{
MessageBox.Show(P.Name);
//part below not relevant for question
if (P.Name.StartsWith("LibImage"))
{
i++;
IMG = Image.FromFile(P.DefaultValue.ToString());
PanelImgAr[AmountOfImages] = new SelectablePanel()
{
Size = new Size(150, 84),
Location = new Point(0, -84 + (94 * i)),
BackgroundImage = IMG,
BackgroundImageLayout = ImageLayout.Stretch
};
PanelImgAr[AmountOfImages].Click += new EventHandler(SelectablePanel_Click);
PanelImages.Controls.Add(PanelImgAr[AmountOfImages]);
}
}
But the MessageBox gives me no names. This is probably because Settings.Default.Properties loops through App.config. Can anyone tell me how I loop through user.config? Or how I add the settings in user.config to App.config?
parse the full path of your user.config file to an XDoc. from here on you can read it as a char array.