Pages

Showing posts with label SharePoint Timer Jobs. Show all posts
Showing posts with label SharePoint Timer Jobs. Show all posts

Thursday, March 16, 2017

Add Web Application property bag using Power Shell and use them in SharePoint timer job

Introduction

SharePoint Web Application level property bag is used to store configuration setting data and information. I make use of the property bag when I write a timer job.

I store value in property bag as key, value using power shell and using C# server object model I retrieve and make use of it.

Set Web Application Level Property Bag

You can create a function in Power shell

 function SetWebApplicationPropertyBag ($webAppUrl, $key, $value) {

	$Web = Get-SPWebApplication -Identity $webAppUrl
	$Web.Properties.Add($key,$value) #add property bag
	$Web.Update()

	Write-host "Created new Property:" $Web.Properties[$key]
 
 }

And you can call the function like this.

$webAppUrl ="Web Application url goes here"
$PropertyName1 ="Key"
$PropertyValue1 ="Value"

SetWebApplicationPropertyBag $webAppUrl $PropertyName1 $PropertyValue1

You have to change the values of $webAppUrl, $PropertyName1 and #PropertyValue1.

Copy paste code in SharePoint Management shell and your web application property will be created.

Retrieve property bag value in SharePoint Timer Job

Since SharePoint Timer Jobs are created with the feature, in Web Application level scope, we can use the below code to retrieve the data.

var value = WebApplication.Properties["Key"].ToString();

You can make use of value and do operations.

Remove Property Bag

You can use below code to remove a value from property bag.

$Web = Get-SPWebApplication -Identity "Web Application Url"

$Web.Properties.Remove("Key")

$Web.Update()

Monday, June 16, 2014

Work Item Timer Jobs - Presentation

Sri Lanka SharePoint Forum June 2014 offline meeting happened on June 11th. My tech lead Dinusha Kumarasiri did the first session on “How to use Provisioning Providers” and I did the second session on “Work Item Timer Jobs in SharePoint”.
This is my first ever session on SharePoint forum and also the first session on a public forum. I would like to thank Prabath Fonseka and Wellinton Perera for providing me with this opportunity, and also would like to extend my thank all the participants.
10393838_10152318026097530_3673986027299882108_n

 

Source Code

https://drive.google.com/file/d/0ByEnOE8DAdvhbkphQlpacWlySkU/edit?usp=sharing

 

Photos