Delete the Merge Documents and Relink Documents views on a forms library

I recently came across a situation where I needed to remove the “Merge Documents” and “Relink Documents” views on a forms library so that the users wouldn’t hurt themselves.

deletemergeview01

I think the “Merge Documents” link is created because of the setting shown below in InfoPath Form Options although I have not verified this.

deletemergeview02

These views do not show up in the Views section at the bottom of the Library Settings so there is no easy way to delete them. I checked in SharePoint Manager 2013 and could see the views but not delete them for some reason even though I had permissions.

So I wrote the following PowerShell script to delete the views.

####################################################################################################
#
#  Author.......: Khalid Ansari
#  Date.........: 08 Nov 2013
#  Description..: Delete Merge and Relink views on a SharePoint list
#  Parameters...: [Required] SiteUrl = Url of site
#				  [Required] ListDisplayName = Display name of list
#
####################################################################################################
param(
	[parameter(Mandatory=$true)] [string] $SiteUrl
	, [parameter(Mandatory=$true)] [string] $ListDisplayName
)

function DeleteView([object] $list, [string] $viewName)
{
	$view = $list.Views[$viewName]
	if ($view)
	{
		Write-Host "Found view $($view.Title). Deleting view..."
		$list.Views.Delete($view.ID)
		$list.Update()
		$view = $list.Views[$viewName]
		if (!$view)
		{
			Write-Host "View deleted"
		}
	}
	else
	{
		Write-Host "View $($viewName) not found"
	}
}

$spAssignment = Start-SPAssignment

$web = Get-SPWeb $SiteUrl
$list = $web.Lists[$ListDisplayName]

DeleteView $list "Merge Documents"
DeleteView $list "Relink Documents"

$web.Dispose()

Stop-SPAssignment $spAssignment

You could argue that they should not be deleted because they have some useful reason for being there and that is entirely possible, but in this instance I needed to zap them since merging of the InfoPath documents would have caused havoc with the clients business process and life is too short to spend time explaining relinking to an end user.

Leave a Reply

Your email address will not be published. Required fields are marked *