2

I am taking over and modernizing a model from another developer.

They had the following line in the settings.ascx page of the Module settings:

 DotNetNuke.Entities.Portals.PortalSettings.UpdatePortalSetting(this.PortalId, "setting_name", tx_emailfrom.Text);

Which throws the following warning

Warning 'PortalSettings.UpdatePortalSetting(int, string, string)' is obsolete: 'Deprecated in DNN 5.0. Replaced by DataProvider.UpdatePortalSetting(Integer, String, String)'

So I changed the line to:

DotNetNuke.Data.DataProvider.UpdatePortalSetting( this.PortalId, "setting_name", tx_emailfrom.Text, UserId, "en-US");

As suggested but now I get the following error:

Error CS0120 An object reference is required for the non-static field, method, or property 'DataProvider.UpdatePortalSetting(int, string, string, int, string)'

What is the most up to date way to update the portal settings for DNN 7.3 and above. I can get the portal settings, just having trouble updating them.

Thanks in advance.

VDWWD
  • 35,079
  • 22
  • 62
  • 79
J King
  • 4,108
  • 10
  • 53
  • 103

2 Answers2

3

The following is how I solved it

One note, this answer is for "custom" portal settings. So VDWWD's solution works for all existing portal settings of the portal object.

I fixed this my adding .Instance() to the following line:

 DataProvider.UpdatePortalSetting( this.PortalId, "bulletin_sendemail_from", this.tx_emailfrom.Text, UserId, "en-US");

is changed to

 DataProvider.Instance().UpdatePortalSetting( this.PortalId, "bulletin_sendemail_from", this.tx_emailfrom.Text, UserId, "en-US");

And now it works

J King
  • 4,108
  • 10
  • 53
  • 103
1

Here you go...

using DotNetNuke.Entities.Portals;

//get the current portal settings
PortalInfo portalInfo = PortalController.Instance.GetPortal(PortalId);

//overwrite a specific setting
portalInfo.PortalName = "My New Portal Name";

//save the new portal settings
PortalController portalController = new PortalController();
portalController.UpdatePortalInfo(portalInfo);

You may need to clear the cache for the new settings to take effect.

DotNetNuke.Common.Utilities.DataCache.ClearPortalCache(PortalId, false);
VDWWD
  • 35,079
  • 22
  • 62
  • 79
  • thanks for the suggestion, but the setting I am talking about is a "custom" setting and is not a property of the PortalObject. – J King Oct 21 '16 at 14:59