Appsetting!! am I doing it right?  
Author Message
Fahd





PostPosted: Visual C# General, Appsetting!! am I doing it right? Top

basically, I need to save two strings for my app (Upload and Download) so I can retrieve them on app startup. what I did, I created a setting file under project properties. This is how I save and load them:

//to save the settings

private void button2_Click(object sender, EventArgs e)

{

Properties.Settings.Default.Upload = tbUp.Text;

Properties.Settings.Default.Download = tbDownload.Text;

Properties.Settings.Default.Save();

Properties.Settings.Default.Reload();

this.Close();

}

//to load the settings

private void frmOptions_Load(object sender, EventArgs e)

{

tbUp.Text = Properties.Settings.Default.Upload;

tbDownload.Text = Properties.Settings.Default.Download;

}

I don't know if I'm doing right, it saves the settings though but I just need to know the right way to do it, please help. It used to be way easy with ini....

Fahd



Visual C#19  
 
 
Reinout Waelput





PostPosted: Visual C# General, Appsetting!! am I doing it right? Top

Those (Properties.Settings.Default) are usersettings, placed in the "Documents and Settings\[user]\Local Settings\Application Data\[app_name]\[assembly_version]\"-folder. If that's what you want, it's correct.
The Reload() method is not necessary since you just saved them anyway. This method could be useful when you update a setting - e.g. Upload -, and don't save it, when you do a reload without the saving you'll get (back) the original value for the properties. When reloading after running the save() method, you basically just load what you just saved - and what is already in the property-values - so it's useless.

Actually, why do you ask it You get any errors / exceptions



 
 
Fahd





PostPosted: Visual C# General, Appsetting!! am I doing it right? Top

I'm asking because I'm new to .NET and I'm not sure if I'm doing right. no I don't get any error msg, it works just fine. what I want is to know if this method is the correct way for what I want. ie: my app does this:

upload and download zip files, and in order to customize the path of the upload and the download folder, I want to be able to save the paths somewhere like ini file, but I don't want to use Win32API. I thought the framework is got to come with something similar even better, efficent and user friendly. And this is what I came up to Properties.Settings!!

so I'm not sure!!

thanks for your reply!!

Fahd