Archive

Posts Tagged ‘SharePoint’

SharePoint 2013 – Read List Items using REST API

December 23, 2014 1 comment

SharePoint 2013 introduced Rich REST endpoints, we can use this to query data asynchronously using jQuery/JavaScript.

Here is a sample code which can be used to read items from a SharePoint list

var siteUrl = window.location.protocol + "//" + window.location.host + _spPageContextInfo.siteServerRelativeUrl;

jQuery.ajax({
	url: siteUrl + "/_api/lists/getbytitle('ListTitle')/Items?$select Title",
	type: "GET",    
	headers: { 
		"accept": "application/json;odata=verbose",
		"content-type":"application/json;odata=verbose",
		"X-RequestDigest": jQuery("#__REQUESTDIGEST").val()
	},
	success: function(d) {
		var stringData = JSON.stringify(d);
		var jsonObject = JSON.parse(stringData);
		var results = jsonObject.d.results;
		for(i = 0; i < results.length;i++) {
			console.log(results[i]["Title"])
		}
	},
	error: function() {
		console.log('fail');
	}
});

We are dynamically forming the site url using various tokens.

First we need to get the SharePoint list, for that we use REST method GetByTitle and pass the list title. Then we are selecting the item Title. You can add more fields by separating with comma.

The result is then converted to JSON object using JSON.Parse method.

Finally a loop is used to iterate through the items.

Categories: SharePoint 2013 Tags: , , ,

SharePoint 2013 – Hide page title

December 4, 2013 7 comments

Here is a snippet which can be used to hide page title. All you need to do is edit the master page and place the script inside head tag

<script type="text/javascript">
	function hidePageTitle() {
		var elem = document.getElementById('pageTitle');
		elem.style.display = 'block';
	}

	_spBodyOnLoadFunctionNames.push("hidePageTitle"); 
</script>

SharePoint – Custom approval workflow with Dynamic Approvers using SharePoint Designer

March 14, 2013 6 comments

In this article I will walk you through on how to implement a custom document approval workflow using SharePoint Designer.

Assuming the person to approve is set through a metadata property of the document.

Below snapshot show how the Document library looks

WFL1

Let’s start the process by opening site in SharePoint designer. From Ribbon, click on List Workflow and select the document library.

WFL2

Enter workflow name and description

WFL3

Now add action “Start Approval Process” from ribbon

WFL4

Edit step by clicking “these users” link

WFL5

Here we are going to select the dynamic approver by picking the user from current item property

WFL6

WFL7

WFL8

WFL9

Click Ok. Now select “Workflow Settings” from ribbon

WFL90

From start options we should set “Start workflow automatically when an item is created”. This will ensure for all new document uploaded into the library will go through an approval process.

WFL91

Last step is to publish the new workflow.

WFL92

Lets test the workflow. Step 1 is to verify whether the workflow got associated properly. For that open up the document library setting and open the Workflow settings.

WFL93

Let’s upload a new document. Ensure to put a valid user in “Approver” field.

WFL94

Now the workflow will kick start and the status will be “In Progress”

WFL95

A new task should get created for the Approver.

WFL96

Clicking on the Task title will bring up the “Approve/Reject” option

WFL97

Clicking Approve will complete the workflow.

WFL98

That’s all. Hope this helps.

Thanks!

PowerShell – Delete all files & folders from SharePoint library

February 26, 2013 8 comments

The good thing about PowerShell is that we don’t need to compile anything. Just write the script and execute.

In this article I am going to share a very useful PowerShell script which can be used for clearing SharePoint document library.

Add-PSSnapin Microsoft.SharePoint.PowerShell

# Replace siteurl with actual web url
$web = Get-SPWeb -Identity "siteurl"
# Replace docurl with document library url
$list = $web.GetList("docurl")

function DeleteFiles {
    param($folderUrl)
    $folder = $web.GetFolder($folderUrl)
    foreach ($file in $folder.Files) {
        # Delete file by deleting parent SPListItem
        Write-Host("DELETED FILE: " + $file.name)
        $list.Items.DeleteItemById($file.Item.Id)
    }
}

# Delete root files
DeleteFiles($list.RootFolder.Url)

# Delete files in folders
foreach ($folder in $list.Folders) {
    DeleteFiles($folder.Url)
}

# Delete folders
foreach ($folder in $list.Folders) {
    try {
        Write-Host("DELETED FOLDER: " + $folder.name)
        $list.Folders.DeleteItemById($folder.ID)
    }
    catch {
        # Deletion of parent folder already deleted this folder
    }
}

SharePoint – Display Search Result as Raw XML

January 29, 2013 1 comment

Search results are formatted on screen using XSLT’s. At times the XSLT’s will not give back the result was were expecting. In such cases we need to debug to find the root cause. To start with the first step I will do is by checking the search results in Raw XML format. This helps me to rule out issue with Search vs. Issue with XSLT’s

To display data in XML we should use following in the XSL Editor of Search webpart

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />
<xsl:template match="/">
<xmp><xsl:copy-of select="*"/></xmp>
</xsl:template>
</xsl:stylesheet>

OOB by default custom XSL is disabled. To enable it

  • Open properties of “Search Core Results” webpart
  • Un-check property “Use Location Visualization”

WV-4

SharePoint – Word Web App cannot open this document for viewing because of an unexpected error

January 29, 2013 1 comment

Today I saw a strange error with office web app. I was unable to open up any of the office documents in office web apps. Clicking the document link simply throws following error

WV-Error

I search ULS log files and found following exception details

System.AccessViolationException: Attempted to read or write protected memory. 
This is often an indication that other memory is corrupt.

To resolve this I execute following steps. For simplicity I am using Word as an example.

  1. Ensure Word Viewing service is started
    • Central Admin -> System Settings -> Manage services on server -> Word Viewing Service
    • WV-1
  2. Stop the Word Viewing service and start it
  3. Ensure Word Viewing service proxy is created
    • Central Admin -> Application Management -> Manage service application
    • Look for following
    • WV-2
  4. Ensure Word Viewing service proxy is associated with proxy group
    • Central Admin -> Application Management -> Manage web applications
    • Select the Web Application. From ribbon click on Service connections
    • WV-3

This resolved the issue and I was able to open up office documents in office web apps.

SharePoint – Exclude Document Library From Search

January 29, 2013 1 comment

Navigate to document library setting. From the setting page select “Advanced Settings” and use following property.

Allow items from this document library to appear in search results?

Library Advanced Setting