Especially in SharePoint Online it could be difficult to make the content of the property bag for a site visible. With JavaScript in SharePoint 2013 or SharePoint Online this task could be done very easy. Just save the following script to a file and upload this file to the SiteAssets library in the SharePoint site. Create a new page in the SharePoint site and put a Content Editor webpart onto this page. Set the script url in the properties of the Content Editor webpart to the url to the uploaded script file. After saving and reloading the page click the button to display the web properties.

<style>
.webPropertyRow {
	padding-left: 4px;
	padding-right: 4px;
}
</style>

<script type="text/javascript" language="javascript">

	var clientContext = null;
	var web = null;
	var properties = null;

	function runCode() {
        this.clientContext = new SP.ClientContext.get_current();

        if (this.clientContext != undefined && this.clientContext != null) {
            this.properties = clientContext.get_web().get_allProperties();
			
			this.clientContext.load(this.properties);
			
			this.clientContext.executeQueryAsync(
				Function.createDelegate(this, this.gotWebProperties), 
				Function.createDelegate(this, this.onQueryFailed));
		}
	}
	
	function gotWebProperties() {
		document.getElementById("webProperties").innerHTML = "&nbsp;";
		
		var table = document.createElement("table");
		table.setAttribute("border", "1");
		
		var allProperties = this.properties.get_fieldValues();
		
		for (property in allProperties) {
			var row = document.createElement("tr");
			
			var cell1 = document.createElement("td");
			cell1.setAttribute("class", "webPropertyRow");
			
			cell1.innerHTML = property;
			
			var cell2 = document.createElement("td");
			cell2.setAttribute("class", "webPropertyRow");
			
			cell2.innerHTML = allProperties[property];
			
			row.appendChild(cell1);
			row.appendChild(cell2);
			
			table.appendChild(row);
		}
		
		document.getElementById("webProperties").appendChild(table);
	}
	
    function onQueryFailed(sender, args) {
        alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
    }

</script>

<input id="Button1" type="button" value="Show Web Properties" onclick="runCode()" />
	
<br />
<div style="margin-top:20px;">&nbsp;</div>

<div id="webProperties"></div>

Advertisements