Home > Sharepoint > Configuration Values in SharePoint 2010 Timer Job

Configuration Values in SharePoint 2010 Timer Job


Hi All,

                      1. When we develop custom timer job in SharePoint 2010 most of the time we might need to store some config

values    which    can  be utilized while activating the feature or during the execution of the timer job.

                      2. Some of us may think about the use of config list and fetch the data from there when we move the package

from dev.  environment to other environment we should also carry over the configuration list along with site url where the

config list resides.

                      3. In order to remove from these kind of pain SharePoint is having an awesome feature called Property bag .

MSDN reference contains Property bag implementation in details

http://msdn.microsoft.com/en-us/library/ee855123(v=office.12).aspx

Below is Powershell script which can be used to create property bag values

-----------------------------------------------------------------------------------------------------------------------------

$snapin = Get-PSSnapin | Where-Object {$_.Name -eq ‘Microsoft.SharePoint.Powershell’}
if ($snapin -eq $null) {
Write-Output “Loading SharePoint Powershell Snapin”
Add-PSSnapin “Microsoft.SharePoint.Powershell”
}

# —————————————————–
Write-Output “Task initialized…”

$weburl= “http://../sites/test/Implemetnation”
$url= [System.Web.HttpUtility]::UrlDecode($weburl)
$site = New-Object Microsoft.SharePoint.SPSite($url)
$rootWeb = $site.RootWeb

Write-Host -foregroundcolor Green “The current Site”$rootWeb

$PropertyKey = “siteUrl”

$webvalue= “/Implemetnation”
$PropertyValue = [System.Web.HttpUtility]::UrlDecode($webvalue)

 

$rootWeb.AllowUnsafeUpdates = $true;
$Currentvalue = $rootWeb.Properties[$PropertyKey]
Write-Host -foregroundcolor Green “The current value of the property bag is “$Currentvalue

if (!$rootWeb.Properties.ContainsKey($PropertyKey))
{
$rootWeb.Properties.Add($PropertyKey, $PropertyValue);
}
else
{
$rootWeb.Properties[$PropertyKey] = $PropertyValue;
}

$rootWeb.Properties.Update();
$rootWeb.Update();
$rootWeb.AllowUnsafeUpdates = $false;

$UpdatedValue =  $rootWeb.Properties[$PropertyKey]
Write-Host -foregroundcolor Green “Value of the property bag is updated with ” $UpdatedValue
if ($rootWeb -ne $null)
{
$rootWeb.Dispose()

}
If ($site -ne $null)
{
$site.Dispose();
}

Write-Host -foregroundcolor Green “Script has finished executing ”
Write-Output “Task completed…”

———————————————————————————————————————————————————————-

 

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: