Witam!
Chciałem napisać funkcję która będzie sprawdzać nazwę aktualnie zalogowanego użytkownika i przypisywać dla niej ścieżkę folderu( zmiana wartości string ). Stworzyłem plik konfiguracyjny app.config podzielony na dwie sekcje( user i path ). Umiem pobrać i przypisać wartość, lecz niestety tylko pojedynczo, a chciałbym żeby ta funkcja się zapętlała.
Funkcja( dla testów zamiast pobierania nazwy użytkownika użyłem textboxa, a dla otrzymanej wartości label ):
[code]
//klucz pierwszy
string userName = string.Empty;
string userPath = string.Empty;
var userSection = ConfigurationManager.GetSection("user") as NameValueCollection;
var pathSection = ConfigurationManager.GetSection("path") as NameValueCollection;
userName = userSection["1"].ToString();
userPath = pathSection["1"].ToString();
if (textBox1.Text.ToString() == userName)
{
label1.Text = userPath;
}
//klucz drugi
string userName2 = string.Empty;
string userPath2 = string.Empty;
var userSection2 = ConfigurationManager.GetSection("user") as NameValueCollection;
var pathSection2 = ConfigurationManager.GetSection("path") as NameValueCollection;
userName2 = userSection2["2"].ToString();
userPath2 = pathSection2["2"].ToString();
if (textBox1.Text.ToString() == userName2)
{
label1.Text = userPath2;
}
[/code]
Plik app.config:
[code]
<configSections>
<section name="user" type="System.Configuration.NameValueSectionHandler" />
<section name="path" type="System.Configuration.NameValueSectionHandler" />
</configSections>