[global::System.Configuration.UserScopedSettingAttribute()]

  [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]

  [global::System.Configuration.DefaultSettingValueAttribute('password')]

  public string Password {

   get {

    return ((string)(this['Password']));

   }

   set {

    this['Password'] = value;

   }

  }

 }

}

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>

  <PhotoViewer.Properties.Settings>

   <setting name='FTP_SERVER' serializeAs='String'>

    <value>ftp://127.0.0.1</value>

   </setting>

   <setting name='UserName' serializeAs='String'>

    <value>anonymous</value>

   </setting>

   <setting name='Password' serializeAs='String'>

    <value>password</value>

   </setting>

  </PhotoViewer.Properties.Settings>

 </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 {

 enum WebRequestMethod {

  MakeDirectory,

  DownloadFile,

  ListDirectoryDetails,

  RemoveDirectory,

  DeleteFile

 }

Declare the following constants and member variables:

public partial class Form1 : Form {

 //---constants for the icon images---

 const int ico_OPEN = 0;

Вы читаете C# 2008 Programmer's Reference
Добавить отзыв
ВСЕ ОТЗЫВЫ О КНИГЕ В ИЗБРАННОЕ

0

Вы можете отметить интересные вам фрагменты текста, которые будут доступны по уникальной ссылке в адресной строке браузера.

Отметить Добавить цитату