Tags

Most time you need to use a property in your class project. .Net has made it very easy.

For example you have MyDemoWeb Project and a class library called MyClass.

Create a app.config file in MyClass, add setting in Properties, choose Application Scope.

Don’t View Code otherwise it will generate a setting.settings.cs file. Go to the properties of Settings.settings, replace “PublicSettingsSingleFileGenerator” in custom tools. Build the project.

Now open web.config & app.config,

Copy

        <sectionGroup name=”applicationSettings” type=”System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089″ >
            <section name=”MyClass.Properties.Settings” type=”System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089″ requirePermission=”false” />
        </sectionGroup>

in your <configSections> section of your web.config

and   put following in <configuration> of your web.config

<applicationSettings>
    <MyClass.Properties.Settings>
      <setting name=”FullName” serializeAs=”String”>
        <value>Ken Zheng</value>
      </setting>
    </MyClass.Properties.Settings>
  </applicationSettings>

Then in your code write l

blProperty.Text = MyClass.Properties.Settings.Default.FullName;

You Can download example code from

http://cid-5e2b95139edcd772.skydrive.live.com/self.aspx/CodeExample/MyDemoWeb.rar

Advertisements