Archive for February 28, 2011

How to Prevent SharePoint 2010 users from using SharePoint Designer



SharePoint Sites can be edited using SharePoint Designer for customizing the user interface and other purposes. But at times, it could potentially affect the performance of sites. In such cases, some administrators prefer to not to allow customization using SharePoint Designer.


Not only can SharePoint 2010 limit users from using SharePoint Designer 2010 but it can also stop users from detaching pages, customizing the master page and layout pages and it even preventing the change of the Web Site URL Structure. In this article, we will look into how to stop users from editing the site using SharePoint Designer 2010. 

Go to Central Administration -> Application Management:

Under Web Application, click Manage Web Applications. 

Select the application on which you want to restrict all users from using SharePoint Designer 2010. Click on the application name. 

A ribbon will be available at the top once you select the application. Click on general settings and then on SharePoint Designer. 

A box will be prompted with some options.To restrict user, uncheck the “Enable SharePoint Designer” checkbox. Click OK. 

Now go to any site page. Click on the “Page” Tab on Ribbon. Click on Edit and then on “Edit in SharePoint Designer”. Enter the credentials. Once you enter the needed credentials, you will be prompted with an error describing that the user is not allowed to edit site in SharePoint Designer (see image below). 

One can use this feature to stop every user from accessing the SharePoint site using SharePoint Designer.

Show and hide columns in SharePoint list forms with PowerShell


One of the great things about PowerShell with SharePoint 2010 is the ability to configure settings that are not available through the browser interface by writing a simple script, rather than having to load up Visual Studio and develop a custom application to access the Object Model. This article covers how to set properties on columns in order to show or hide them from specific list forms.

The following table taken from MSDN shows the properties available to us:

Gets or sets a Boolean value that specifies whether the field is displayed in the form for displaying list items.

Gets or sets a Boolean value that specifies whether the field is displayed in the form that is used to edit list items.

Gets or sets a Boolean value that specifies whether the field is displayed in the page for customizing list settings.

Gets or sets a Boolean value that specifies whether the field is displayed in the form that is used to create list items.

Gets or sets a Boolean value that specifies whether the field is displayed in the page for viewing list item versions.

Gets or sets a Boolean value that specifies whether the field is displayed in pages that are used to view list data.

For this example, I am going to disable the ShowInEditForm properties for a column called “Test Column” that I have created directly in a document library (I’ll deal with site columns later). Here is a screenshot of the edit form when I upload a new document to the library or edit the properties of an existing document:


I then run the following PowerShell Script:

#Get the web, list and column objects
$web = Get-SPWeb http://portal
$list = $web.Lists[“Shared Documents”]
$column = $list.Fields[“Test Column”]

#Change the ShowInEditForm property and update objects
$column.ShowInEditForm = $false

Now when I edit the properties of the document, the Test Column is no longer there:


However, because the ShowInDisplayForm property is still set to true, the column does appear when I view the properties of a document:


The script is different if you want to achieve the same thing with a site column. I used the following script to modify the ShowInEditForm property of a site column called “Test Site Column”, which can be added to document libraries and lists directly, or through a content type. Note that the new ShowInEditForm property setting will apply to all document libraries, lists and content types where the site column has been added:

#Get the web and site column objects
$web = Get-SPWeb http://portal
$column = $web.Fields[“Test Site Column”]

#Set the PushChangesToLists property for the changes to be applied
#to lists where the column has already been added
$column.PushChangesToLists = $true

#Change the ShowInEditForm property and update objects
$column.ShowInEditForm = $false

Generating short description using the Content Query Web Part

Let’s take the following case as an example: you have a subsite with Press Releases and would like to display the 5 most recent one on the home page. To make it more interesting to the visitors you would like your press releases roll-up to show the date, the title and a couple of lines of content of each press release. Having configured it using the CQWP you get the following output:

Anything odd about it? Instead of seeing the short description the content roll-up shows the whole content. Sure you could ask the content editors to enter the short description in the Description field but as a good citizen you want to keep the content management process as simple as possible.

So what do we have available that might help us solve us this issue?

Out of the box methods for generating short descriptions

XPath substring function

First thing you might want to use is the XPath substring function. The substring function takes the following parameters: the string which you want to process, the start position for extracting the substring and the optional third parameter which allows you to define how many chars you want to extract. Let’s take a look at the following example:

See the problem? The substring function is not aware of the HTML markup and therefore using it has the risk of breaking the markup of the whole page! If only we could strip the HTML markup before passing it to the substring function…

XPath string replacements

XPath in its standard implementation doesn’t contain any function for replacing one string with another. Neither does the ddwrt namespace. There is a replace function in the EXSLT namespace but how to make the standard Content Query Web Part understand the EXSLT namespace? There is a .NET implementation of the EXSLT functions but it would mean that you would have to subclass the standard CQWP and extend theModifyXsltArgumentList method.

And even if there was a replace function available, it would have to support Regular Expressions (RegEx): how else would you replace all HTML? There is no simple string equivalent of the simple <[^>]+> RegEx pattern used to strip string of all HTML markup.

But isn’t there anything we could do using nothing else than the out-of-the-box functionality? There is one thing…

Custom template for generating short descriptions

The Content Query Web Part uses three separate XSLT files to render the output. The best part is that you can extend each one of them or even make the CQWP use one of your custom files. Given such flexibility we could create a custom XSL template to do the job for us.

Before we dive into the code let’s define the requirements.

First of all we want to be able to generate a short preview of the content starting at the beginning of the string and containing x chars.

We want the short summary to be HTML safe: all HTML markup should be removed before generating the short description. Also the length of the short description should be calculated using the string with HTML removed.

As a nice-to-have it would be great to be able to include some kind of suffix like “…” or “more” if the content turned out to be longer than the short description allows and has been shortened.

Removing HTML markup in XSLT

As we have already found out there is no standard functionality available in XSLT to remove HTML markup. What we can do though, is to define templates which in some way resemble functions: pieces of logic which you can call with different parameters.

We’ve already done this, so what we can do is to grab the existing template and use it in our solution.

The first part of our requirement is complete: we can strip a string of all HTML markup.

Imtech.GenerateSummary template v0.1

By now we should be able to write a simple template to generate short descriptions for us:

That should do the job, right? Well, there is one problem… Let’s have a look at a test case:

Lorem ipsum dolor sit amet, consectetur
adipiscing elit. Nunc a magna quis velit dapibus blandit.
Pellentesque accumsan tortor ut est

Curious what the result is? “Lorem ipsum dolor sit amet, consectetur adipi”. In case you haven’t noticed the word adipiscing is being sliced in the middle. Not really nice, is it? We should know better nowadays.

That leads us to a new requirement: the short description should be of maximally the given length, but if it’s in a middle of a word, the function should go back until it finds a separator (space in our case) and break the short description there. According to this requirement the short description in the example above should be “Lorem ipsum dolor sit amet, consectetur”.

LastIndexOf in XSLT?

If you were programming in one of the .NET languages you would use the LastIndexOf function to determine the position of the last separator and substring the initial string to that position. Want to hear some bad news? There is no LastIndexOf in XSLT. Somehow you don’t seem very surprised…

Once again let’s use templates to get the job done. Instead of returning the position of the last separator, we will immediately return the string before the last separator.

select="substring-after($String, $Char)" />

This template takes two parameters: the string which you want to create a substring of and the character you’re looking for. The third parameter (subsequent) is for internal purposes: it helps the template to determine whether it should output a separator or not.

How it works

First of all the template checks whether the given string contains the character passed through the Char parameter. If the character has been found the string is being passed for further processing. If not the template checks one more thing: if it’s the initial call (subsequent parameter hasn’t been set yet), the string is being output as-is (this to cover the following case SubstringBeforeLast(“Lorem”, “ ”)).

If the template finds the Char character in the string: first the template checks if it is a subsequent call or not. As separators are not being included in the String variable on subsequent calls this check is required to include all other separators than the last one. Then everything before the first occurrence of the separator is being passed to the output. Everything after the separator is being used as the String parameter for a recursive call. Additionally the subsequent parameter is being set to let the template know that it’s being called from itself.

Almost there

So far we have done a lot of work with the XSLT. Let’s put it together and have a look at the result:

Using a custom XSLT template you can easily get the short description displayed properly. One last thing missing is adding a suffix like '...' after shortening a string

Almost there, aren’t we? The last thing that we’re missing is appending a suffix after shortening the content. Let’s finish our template off with this feature:

And just a last check to confirm that it’s all working properly:

Using a custom XSLT template you can generate a properly displayed short description using the full page content as input

The complete short summary template by now should look like this:

select="substring($cleanContent, 1, $Length)"/>


select="substring-after($String, '>')"/>

select="substring-after($String, $Char)" />

And you can use it like this:


Content Query Web Part is a very powerful and flexible Web Part. Because it uses XSLT for data presentation it allows you to generate dynamic content aggregation matching your branding and requirements. Although the default XSLT implementation supported by the CQWP contains only the basic functionality, you can easily extend it with custom templates. While they seem more complex than a comparable solution using C# or VB the best part is, that they don’t require any custom code and work in any standard MOSS 2007 installation.

Add an Input Box to Your SharePoint 2010 PowerShell Scripts


For all of you busy SharePointers out there, this may be a helpful addition to your PowerShell scripts. Adding an input box to a script allows it to be reusable instead of only for a certain web app, site collection, or site. Think of it as an interactive way of passing parameters into PowerShell commands. It’s simple and easy, here’s how:

Add to the top of your script:


Call the input box and store the results in a variable:

$var_name = [Microsoft.VisualBasic.Interaction]::InputBox(“Input Description”, “Window Title”)

Use the variable where needed in your PowerShell script:

Get-SPLogEvent| ?{$_.level –eq $var_name} | select Category, Message | more