The idea is taking some settings into DotNetNuke without:
- Creating a new table
- Writing sql scripts
- Using nuke api.
- Using simple key-value pairs
- Using fresh technologies (this time DotNetNuke at 5.5)
First of all, let's search where we can store key-value pairs in the DotNetNuke database. After some search I found two suitable tables: PortalSettings and HostSettings:

At my solution, I use host settings because I need them at multiple portals. I didn't check but I think you can do similar with portal settings too. CreatedByUserID values are existing users in our portal. Default settings that set during the installation has -1 CreatedByUserID value.
Now we know where we want to put our key-value pairs, the question is: how?
After using google a bit and trying many (really many) obsolete methods I found a solution that maches for my DotNetNuke version (5.5).
Steps are:
1.: Usings. Many blogs, forums, documentations telling you what to do but you don't know a bit information: Wich namespaces do I need?
using System; using System.Linq; using DotNetNuke.Entities.Controllers; using DotNetNuke.Entities.Modules; using DotNetNuke.Services.Exceptions; using DotNetNuke.Data;
3.: We need a texbox for showing the results (markup):
<asp:Label runat="server" ID="lblSetting" BackColor="AntiqueWhite"/>
2.: Create custom host setting (C#):
var dp = DataProvider.Instance();// -2 Not an existing user
// Signature: AddHostSetting(
// string SettingKey// , string SettingValue// , bool SettingIsSecure// , int createdByUserID);dp.AddHostSetting("TestKey", "TestValue", false, -2);
3.: Getting Setting value by key (C#):
lblSetting.Text = HostController.Instance.GetString("TestValue");
4. Open a beer and be happy :)
No comments:
Post a Comment