API Questions on Kentico API.
Version 6.x > API > Retrieve custom setting value added for a site. View modes: 
User avatar
Member
Member
anshuman.shandilya-aonhewitt - 1/20/2012 8:06:56 AM
   
Retrieve custom setting value added for a site.
Hi,
I have added a custom setting category and a custom setting in that category, by inserting 1 record each in "CMS_SettingsCategory" and "CMS_SettingsKey" for a specific site.
Now I can see this custom setting under "Site Manager"->"Settings". My category is in the last and it has one setting in it when I open that category. I set value in this setting.
But I am not finding any way to retrieve this setting value in my webpart. Please help me with the API.

Thanks
Anshuman

User avatar
Member
Member
kentico_michal - 1/20/2012 8:42:29 AM
   
RE:Retrieve custom setting value added for a site.
Hello,

You can use methods from the SettingsKeyProvider class, as it shown here:

int keyvalue1 = SettingsKeyProvider.GetIntValue(CMSContext.CurrentSiteName + ".<keyname1>");

OR

bool keyvalue2 = SettingsKeyProvider.GetBoolValue(CMSContext.CurrentSiteName + ".<keyname2>");

Best regards,
Michal Legen

User avatar
Member
Member
anshuman.shandilya-aonhewitt - 1/20/2012 9:59:55 AM
   
RE:Retrieve custom setting value added for a site.
Thank you very much.
Its working :)

User avatar
Certified Developer v6
Certified Developer v6
keiok-lincintegrated - 7/11/2012 4:43:24 AM
   
RE:Retrieve custom setting value added for a site.
I had tried the about code. that's work for getting global settings. however, i cannot get different settings with different site name.

my custom settings categories as below
sites: site1
site2

Category: myCustom
Group: EmailContact
Key: Australia

Global value:
test
value in different sites:
contact@test1.com
contact@test2.com

so that the full keyname should be myCustom.EmailContact.Australia for getting global settings of that key.

I added the same code as above:
string keyvalue = SettingsKeyProvider.GetStringValue(CMSContext.CurrentSiteName + ".myCustom.EmailContact.Australia");

I cannot get keyvalue in different site, always getting Global value = test

User avatar
Member
Member
kentico_michal - 7/11/2012 7:29:50 AM
   
RE:Retrieve custom setting value added for a site.
Hi,

Could you please try use the key name in the GetStringValue method:

string keyvalue = SettingsKeyProvider.GetStringValue(CMSContext.CurrentSiteName + ".Australia");

Best regards,
Michal Legen

User avatar
Certified Developer v6
Certified Developer v6
keiok-lincintegrated - 7/11/2012 8:06:50 PM
   
RE:Retrieve custom setting value added for a site.
oo, ok with your reply, Thank you :)

by logic, the code name on category and group would working as namespace.

Should I modify the code name as following (all in code name field):

Category: myCustom
Group: myCustom.EmailContact
Key: myCustom.EmailContact.Australia

OR actually code name is just any string, used to identify when i call in method/function as parameter.

User avatar
Certified Developer v6
Certified Developer v6
keiok-lincintegrated - 7/11/2012 8:18:02 PM
   
RE:Retrieve custom setting value added for a site.
oops, Key cannot be adding "."

cheers