}
}
The app.config
file is an XML File containing the default values of your application settings. Its content is:
<?xml version='1.0' encoding='utf-8'?>
<configuration>
<configSections>
<sectionGroup name='userSettings' type='System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'>
<section name='PhotoViewer.Properties.Settings' type='System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' allowExeDefinition='MachineToLocalUser' requirePermission='false'/>
</sectionGroup>
</configSections>
<userSettings>
</userSettings>
</configuration>
The highlighted code shows the settings that you added earlier and their default values. When the project is compiled, this app.config
file will be named <assembly_name>.exe.config
and stored in the binDebug (or binRelease) folder of the project. For this project, the filename will be PhotoViewer.exe.config
.
During runtime, any changes made to the application settings' values will cause a user.config file to be created in the following folder:
C:Documents and Settings<user_name><Local SettingsApplication Data <application_name> <application_name>.vshost.exe_Url_iwwpinbgs0makur33st4vnin2nkwxgq1<version_no>
Notice the long string of random characters in the path. The folder name is generated by the system, and each time you have a different folder name.
For this project, the user.config
file will be stored in a folder with a name like this:
C:Documents and SettingsWei-Meng LeeLocal SettingsApplication DataPhotoViewer PhotoViewer.vshost.exe_Url_iwwpinbgs0makur33st4vnin2nkwxgq11.0.0.0
The content of the user.config file looks like this:
<?xml version='1.0' encoding='utf-8'?>
<configuration>
<userSettings>
<PhotoViewer.Properties.Settings>
<setting name='FTP_SERVER' serializeAs='String'>
<value>ftp://127.0.0.1</value>
</setting>
<setting name='UserName' serializeAs='String'>
<value>anonymous1</value>
</setting>
<setting name='Password' serializeAs='String'>
<value>password</value>
</setting>
</PhotoViewer.Properties.Settings>
</userSettings>
</configuration>
Each user (of your computer) will maintain his own copy of the user.config
file.
Coding the Application
Now to code the application. Switching to the code-behind of Form1
, import the following namespaces:
using System.Net;
using System.IO;
Define the WebRequestMethod
enumeration:
namespace PhotoViewer {
Declare the following constants and member variables:
public partial class Form1 : Form {