Hide Web Template

In PowerShell, if you want to remove a web template from the New Site dialog for a specific web, take a look at the following script:

function Remove-SPWebTemplate {
	[CmdletBinding()]
	param(
		[parameter(Position=1,Mandatory=$true)][Microsoft.SharePoint.SPWeb]$web
	)
	process {
		$templateList = New-Object "System.Collections.ObjectModel.Collection``1[[Microsoft.SharePoint.SPWebTemplate, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c]]"
 
		$availableWebTemplates = $web.GetAvailableWebTemplates(1033);
		$availableWebTemplates | Where{ $_.ID -ne 53 } | ForEach-Object {
		     $templateList.add($_)
		}
 
		if ($templateList.Count -gt 0) {
			Write-Host ("Removing Blank Internet web template with from web '", $_.Title, "' at ", $_.Url -join "") -NoNewline
			$web.SetAvailableWebTemplates($templateList, 1033);
			$web.Update()
			Write-Host " - Done." -ForegroundColor Green
		}
		else {
			Write-Host ("No web templates found for web ", $_.Url -join "") -ForegroundColor Red
		}
	}
}
 
Get-SPWebApplication | ForEach-Object {
	$_.Sites | Where { $_.ServerRelativeUrl -ne '/sites/example' } | ForEach-Object {
		$_.AllWebs | ForEach-Object {
			Remove-SPWebTemplate $_
		}
	}
}

Continue reading

Posted in SharePoint | Tagged , | Leave a comment

LDAP Role Provider Argument Exception

If you’re seeing the following error in the ULS logs, hopefully it’ll be as simple a fix for you as it was for me:

LdapRoleProvider.GetRolesFor() exception: {0}.System.ArgumentException: The (&(((ObjectClass=group))(member=CN=Some User,CN=Users,DC=domain,DC=local)) search filter is invalid.

at System.DirectoryServices.SearchResultCollection.ResultsEnumerator.MoveNext()

at Microsoft.Office.Server.Security.LdapRoleProvider.GetRolesFor(String userOrGroupDN, DirectoryEntry groupContainer, LdapDistinguishedNameManager ldapDnManager, List`1& userRoles)

To resolve this error, all that’s required is to updated the Group and User filter values for the role provider in the forms web application and the security token’s web configuration files.

The role provider settings I had looked something like:

<roleManager>
  <providers>
    <add name="SPRoleManager" type="Microsoft.Office.Server.Security.LdapRoleProvider, Microsoft.Office.Server, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" server="domain.local" port="389" useSSL="false" groupContainer="CN=users,DC=domain,DC=local" groupNameAttribute="cn" groupNameAlternateSearchAttribute="samAccountName" groupMemberAttribute="member" userNameAttribute="sAMAccountName" dnAttribute="distinguishedName" groupFilter="((ObjectClass=group)" userFilter="((ObjectClass=person)" scope="Subtree" />
  </providers>
</roleManager>

Notice the values for groupFilter and userFilter((ObjectClass=person).

This is correct for the Central Administration web configuration. For the forms web application and security token’s configuration this should be updated to (&amp;(ObjectClass=person)).

Perform an IIS reset and next time you log in the exception in the ULS log should be resolved.

Posted in Configuration, SharePoint | Tagged , , | Leave a comment

External Content Type Walkthrough

Looking to design your own external content type and deploy it as part of a SharePoint solution? Read on for a walkthrough on how to create one.

First up, the steps are the same for SharePoint 2010 and 2013 and have been carried out using Visual Studio 2012. Visual Studio 2010 will also work.

Before I start the walkthrough, I’ll summarise the goal of this post:

We have a very simple database that contains a couple of tables – Customer and Order. An external content type will be created and via a view on the database, will return a list of customers and their orders. The external content type will only allow read access to this information.

Assumptions:

  • There is a Business Data Connectivity service up and running on the SharePoint farm for the External Content Type (ECT) to be deployed to.
  • The user deploying the solutions containing the ECT, in this case the user running Visual Studio, has adequate permissions to create it in the application service.
  • This is just a demonstration, so there will be a distinct lack of logging, error handling and bad practices such as storing database credentials in plain text within the code, try to ignore this 🙂

Continue reading

Posted in SharePoint | Tagged , | Leave a comment

NullReferenceException using AssetUrlSelector

If you’ve been using the AssetUrlSelector for SharePoint the following may help if you’ve recently started getting the following error in the ULS logs and are not able to view list items.

Error while executing web part: System.NullReferenceException: Object reference not set to an instance of an object.

The cause of this error is likely due to a recent update applied to the server. The most likely candidate is the recent KB update – 2844287MS13-052: Description of the security update for the .NET Framework 2.0 Service Pack 2 on Windows Vista Service Pack 2 and Windows Server 2008 Service Pack 2: July 9, 2013

Microsoft have recently released a hotfix for this issue (and a few others). The hotfix can be downloaded from the Microsoft site here.

I can confirm that after applying this hotfix, the assert URL selector dialog displayed list items without generating an error.

Posted in SharePoint | Tagged | Leave a comment

Cannot Access a Disposed Object – ModelStore

If you use the database schema compare tool in Visual Studio 2012 you may see the following error when trying to compare the database with the source:

Cannot access a disposed object. Object name: ‘ModelStore’

For me, this was arose after installing the June 2013 update 3 for Visual Studio 2012.

I resolved the error by running Clean Solution and rebooting my machine.

Hopefully this helps someone, as the error isn’t exactly helpful 🙂

Posted in Visual Studio | Tagged , | 2 Comments