CSharpFeeds - All your C# feeds in one place.

Sponsors

Thursday, January 11, 2007

CS Dev Guide: SiteSettings

by Keyvan Nayyeri via Keyvan Nayyeri on 1/11/2007 6:09:22 PM

In addition to site configurations, Community Server provides several settings for each site.  Most of these settings have default values and you can set them in Control Panel and web UI.

CommunityServer.Components.SiteSettings is a code representation of all site settings for a specific Community Server instance.

As you know, several Community Server instances can be installed in same database.  Here a property which is named SettingsID comes handy and helps to distinguish each instance (there is also an ApplicationName property to identify site settings).  A SiteSettings object has a one to one relationship with a SettingsID.

By understanding this important key you can start coding against site settings by using static methods in CommunityServer.Components.SiteSettingsManager namespace and CommunityServer.Components.SiteSettings lassSiteSettings has tons of properties and their name suggests their application so I don't step into their details.  Based on your needs you can get or set these settings in your code.

But SiteSettingsManager namespace helps you to get an instance of SiteSettings object or save one.  Here is a brief description about its common methods:

  • AllSiteSettings: Returns an ArrayList of SiteSettings objects.  Each object in this list is for one of installed applications.
  • GetActiveSiteSettings: Returns an instance of SiteSettings object for current application.
  • GetSettingIDs: Returns an array of integers which contains all SettingIDs for installed applications.
  • GetSiteSettings: This method is provided with three different overloads.  They let you to get an instance of SiteSettings object by passing a SettingsID or ApplicationName.
  • Save: Stores data for an instance of SiteSettings object which is passed to it.

Alright, seeing some examples completes this discussion.

Here UpdateCompanyName() method updates the company name for current application then saves it.  In this code first I created a SiteSettings object and set it to current application settings using SiteSettingsManager.GetActiveSiteSettings() then changed company name and used SiteSettingsManager.Save() method to store my change.

void UpdateCompanyName()

{

    SiteSettings settings = new SiteSettings();

    settings = SiteSettingsManager.GetActiveSiteSettings();

    settings.CompanyName = "Telligent Systems";

 

    SiteSettingsManager.Save(settings);

}

In second example UpdateAllCopyrights() method updates copyright notices for all applications.  It gets an ArrayList of all SiteSettings using SiteSettingsManager.AllSiteSettings() then iterates through them and updates all copyright notices.  On each iteration it stores changes by calling SiteSettingsManager.Save().

void UpdateAllCopyrights()

{

    ArrayList settingsList = SiteSettingsManager.AllSiteSettings();

 

    foreach (SiteSettings settings in settingsList)

    {

        settings.Copyright = string.Format

            ("Copyright © {0} - Licensed under" +

            "Creative Commons Attribution 2.5 License.", DateTime.Now.Year.ToString());

        SiteSettingsManager.Save(settings);

    }

}

Now playing: Man On The Line - Chris De Burgh

email it!bookmark it!digg it!

Original Post: CS Dev Guide: SiteSettings

Subscribe

New Feed

Product Spotlight

Recently Updated Sources

Legal Note

The content of the postings is owned by the respective author. CSharpFeeds is not responsible for the contents of the postings. This site is automatically generated and cannot be reviewed for abusive content. If you find abusive content on CSharpFeeds, please contact us. Designated trademarks and brands are the property of their respective owners. All rights reserved.

Advertise with us