CHUVASH.eu

CHunky Universe of Vigourous Astonishing SHarepoint :)

Tag Archives: settings

Settings in Sharepoint_config database instead of appSettings

An alternative to store key-value paired properties in appSettings in web.config we can use Sharepoint_config database by creating our own SPPersistedObject.  First we have to create a class which inherits from SPPersistedObject and decorate its properties with [Persisted]:

namespace Takana.SharePoint
{
    public class Settings: SPPersistedObject
    {
        [Persisted]
        public string DbConString;
 
        public LinkCheckerPersistedSettings() { }
        public LinkCheckerPersistedSettings(string name, SPPersistedObject parent) : base(name, parent) { }
    }
}

Then we must create such an object. Let’s do it in Powershell:

if(-not(Get-PSSnapin | 
	Where { $_.Name -eq "Microsoft.SharePoint.PowerShell"})) { 
	Add-PSSnapin Microsoft.SharePoint.PowerShell }

[Reflection.Assembly]::LoadWithPartialName("takana.sharepoint")
$app = get-spwebapplication http://takana
$configName = "takana.sharepoint.settings"
$farm = [Microsoft.SharePoint.Administration.SPFarm]::Local
$settings = $farm.GetObject($configName, $app.Id, [takana.sharepoint.settings])
if ($settings -ne $null) { $settings.Delete() }             
#Create a new persisted settings object
$settings = New-Object Takana.Sharepoint.settings ($configName, $app)
$settings.DbConString = "Some Connection String"
$settings.Update();

To get a member by name we must use reflection:

public static string FindSettings(string key, SPWebApplication app)
{
  var s = string.Empty;
  try
  {
    var farm = Microsoft.SharePoint.Administration.SPFarm.Local;
    var settings = farm.GetObject("Takana.Sharepoint.Settings", app.Id, typeof(Settings)) as Settings;
      if (settings != null)
      {
        var type = typeof(Takana.SharePoint.Settings);
        var f = type.GetField(key);
        s = f.GetValue(settings) as string;
      }
  }
  catch (ArgumentException ex)
  {
    throw new ArgumentException("Settings could not be found."), ex);
  }
  return s;
}

To prevent errors, we must catch ArgumentException. Pay attention to the constructor of ArgumentException, we provide the original Exception as an InnerException argument and enable a better tracking.

Version 0.2.6: Settings improvement

Now a user can choose what to see on the map. Maybe only bike pumps or everything. To do that I created a new class ListPreferenceMultiSelect extends ListPreference which is more or less taken from DroidWeb tutorial. The source ListPreferenceMultiSelect.java was improved a little bit: The constructor checks if entries are not empty before creating indices. For the second a new method was added: prepareValueToStore, the opposite one of parseStoredValue. Here is my ListPreferenceMultiSelect.java and in the version 0.2.6.

This version was published on the Market and committed to the repository.

Вула Чăвашла

VulaCV - Чăвашла вулаттаракан сайт

Discovering SharePoint

And going crazy doing it

Bram de Jager - Coder, Speaker, Author

Office 365, SharePoint and Azure

SharePoint Dragons

Nikander & Margriet on SharePoint

Paul J. Swider - RealActivity

RealActivity is a specialized Microsoft healthcare services and solution advisory firm.

Cameron Dwyer | Office 365, SharePoint, Outlook, OnePlace Solutions

Office 365, SharePoint, OnePlace Solutions & Life's Other Little Wonders

paul.tavares

Me and My doings!

Share SharePoint Points !

By Mohit Vashishtha

Jimmy Janlén "Den Scrummande Konsulten"

Erfarenheter, synpunkter och raljerande om Scrum från Jimmy Janlén

Aryan Nava

| Blockchain | Serverless Architecture | Microservices Architecture | DevOps | AWS Lambda | Teraform |

SPJoel

SharePoint for everyone

SharePointRyan

Ryan Dennis is a SharePoint Solution Architect with a passion for SharePoint and PowerShell

SharePoint 2020

The Vision for a Future of Clarity

Aharoni in Unicode

Treacle tarts for great justice

... And All That JS

JavaScript, Web Apps and SharePoint

blksthl

Mostly what I know about SharePoint - CommunicoCuspis