Wednesday, August 25, 2010

SP2010 page reacting strange on javascript code through content editor webpart

I’m working on a SP2010 team site for a client. One of the requirements is a graphical view of the traffic news near the clients location. Of course you can do this through SPD2010 and calling a webservice (soap or REST). Another simpel way is adding some javascript code in a hidden content editor webpart. In the Netherlands the ANWB has a nice feature where you can call some javascript code within your HTML page. After this a graphical image is rendered with the most recent traffic news. The image looks like this:


What I did for my customer was adding a hidden content editor webpart on the page (mine was based on the wike template, but this issue happens also on the default default.aspx with webpart zones). Via HTML I selected the Edit HTML source within the content editor webpart.


After this I added the following bit of code…

<script type="text/javascript">
      var anwb_tool="verkeersinformatie";
<script type="text/javascript" src="">

After a couple of seconds the image was rendered. I was a happy man and was already dreaming of drinking my beer when I got home, when I pressed ‘Save and Close’. Suddenly I had 2 rendered images… I returned back to the page, edited the content webpart again and pressed ‘Save and close’ again. Suddenly I had three (yes 3) rendered images… Apparently, every time you hit the ‘Save button’ SP2010 somehow renders the code again and adds another image in the webpart…..


Please try it out yourself. For the javascript code, please visit and copy past the code in a content editor webpart in your SP2010 site.

Within the SP2010 Content Editor Webpart, you now have the option to link to a seperate file to include in your webpart. I put a .txt file in the assets library and typed in the url. This worked and the image is only rendered once.


Question is… Is this a bug (or feature) in SP2010 or just crappy coding from the anwb developer???

Wednesday, June 2, 2010

How to create a security trimmed top link in a WSS 3.0 site


The other day I had this issue with an out of the box WSS 3.0 site. I had created some subsites. While creating the subsite, one of the options is to choose ‘Display this site on the top link bar of the parent site?’ You can either choose Yes or No.


Choosing Yes will of course show the link to this subsite, choosing No will not show the link. Incidentally I choose No in one of my subsites, thus the subsite is not showing in the top link bar of the parent WSS site. It does show in the quick launch bar.


Within WSS 3.0 you have the option through Site Actions, Site Settings, in the Look and Feel column to go to the Top link bar and create your own custom ‘tabs’. I created the subsite3 tab and it did show now on the top link bar. Issue closed, me:1 SharePoint: 0…… Not!!!!!

Security trimmed navigation

Here is where security comes into play. When you create a subsite, automatically SharePoint makes it a security trimmed ‘tab’ or link. Meaning, if you have permissions on this subsite, you’ll see the tab. If not, the tab will not show. Nothing new under the sun is it? Just plain good old SharePoint. However, the tab ‘subsite3’ I just created is NOT, I repeat, NOT security trimmed. BTW, if you had chosen Yes and let the link be displayed on the top link bar and then deleted the link and re-created it, it also would not be security trimmed.

I’ll show you how you can see this in the Top link bar and in a real time scenario.

Through Site Actions, Site Settings, in the Look and Feel column go to the Top link bar. Click on the edit button before ‘subsite1’. Notice that the url is greyed out?


Now go back 1 step and click on the edit button before ‘subsite3’. Notice that the url is NOT greyed out?


Real time scenario

In subsite 1 and 3 I broke the inheritance with the top level Demo site collection and created unique permissions. My demo user ‘Marc Manager’ does NOT have permissions to these subsites. Marc Manager has only got permissions on the top level Demo site collection and Subsite 2.


Now, when I log on with the credentials of Marc Manager, you will see that the ‘Subsite3’ tab is NOT security trimmed. The ‘subsite1’ tab is not show, the subsite3 tab does show because it’s just a link. Notice that in the quick launch the ‘subsite3’ link has dissapeared. This is because when I created the subsite 3 website, I choose the option ‘Display this site on the quick launch of the parent site, YES’, thus making it a security trimmed link.


So obviously, Marc Manager – the guy he is -  sees the subsite 3 link. When he clicks on it, he will get the logical error, and blaming the whole world and IT Pro’s for this not so friendly error message…..


the big questions is.. How can we solve this?

The solution

Okay, ready to dive into some SharePoint Designer? Open up Sharepoint Designer and open the Demo top level site collection website. Always wondered what this Navigation link was?


You can also go in the Menu Bar to Site, and choose Navigation from the pull down menu.

You will get this nice Visio kinda’ tree view of the Demo website. This is called the Navigation Map.


Within SharePoint Designer, in the Navigation Map you can also build you own top link bar links and quick launch links.  Now right-click on the most right Tab ‘The SharePoint Tob Navigation Bar’ and choose ‘View subtree only’. You will see something like this:image

The Sharepoint Top Navigation Bar has 4 nodes under it. One is Home, which point to the Home page of the Top level site and the others are Subsite1, subsite2 and subsite3.

Now right-click the Sharepoint Top Navigation Bar node and click New -> Page. It will add a node under the Sharepoint Top Navigation Bar. Double click it (this is very important that you do this), it will create a untitled htm page (which you can close immediately) and then back on the untitled 1, right-click it. Choose Properties. You will see something like this:


It will allow you to Edit the Hyperlink. If you scroll down, you will see that the Subsite3 site is listed and you could dubbel click it and then select the ‘default.aspx’  and click OK. After this, click once on the untitled 1.html and it will change into the newly created hyperlink. The new added node will point to the Subsite3 now. BTW, the title now shows Subsite3/default.aspx. You can change the title into ‘Subsite 3 security trimmed’ by clicking once on this title. The end results shows something like this:


Save the site and then close Sharepoint Designer. Go back to the WSS Demo site, log into this site with administrator credentials and you will find the Subsite3 security trimmed tab is listed in the Top Link Bar.


Just checking. Again, go to Site Actions, Site Settings, in the Look and Feel column go to the Top link bar.  Click on the edit button before ‘subsite3 security trimmed’. Notice that the url is greyed out?


Almost there. Now go to the edit button before ‘subsite3’ and choose Delete.

Finally, go back to the WSS top level site collection Demo and again login with Marc Managers’ credentials. Marc will now only see the sites he’s got permissions on through the security trimmed top link bar.


Marc Manager is now a happy SharePoint demo user again….

Tuesday, March 23, 2010

Changing the default operator on the SharePoint Advanced Search

In one of my SharePoint projects, the customer asked the following question: “Can you add another operator in the property picker on Advanced Search aspx and can you change that operator into the default operator”?

Out of the Box advanced search

The out of the box Advanced Search page looks like this:


In the last field “Add property restrictions” you have 2 options in you default operator menu: the “Equals” and “does not equals” option. Before the Infra Structure update, you also had the options “contains” and “does not contains”. But Microsoft decided to remove this because these options can heavily decrease performance because expensive Transact-SQL queries are generated in this search scenario. For more information about this, read KB950437.

In my scenario, the customer wanted these options back and set the “contains” as the default operator.

Adding the ‘Contains’ operator

To do this simply go to the  Properties section of the Advanced Search Box configuration, click on the dialog box as seen below and then in the Properties xml on the top of the XML, change the default Value=”False”  into “True”:

     <Option Name=”AllowOpContains” Value=”True”/>


After hitting the Apply button and saving this page, you get the two extra options:


Setting the ‘Contains’ operator as the default value

Now for the second requirement, I searched for a solution in Jquery which could be put in a hidden Content by Editor webpart. With the help of Marc D Anderson (follow him on Twitter @sympmarc) and his Jquery library for SharePoint Web Services website, I found the right code for this.

First of all, download the latest version of the jquery-1.4.2.min.js and put this in the document library that also contains the advanced.aspx. But be welcome to put in in any library of your choice. In the code underneath I make a reference to this jquery-1.4.2.min.js. BTW, always use the minified version in a production environment.

On the advanced.aspx page I have put a hidden Content editor webpart. In the source editor I put the following code, which results in setting the 'contains' operator as the default value:

<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("select[Title='Inclusion Operator'] option[Value='Contains']").attr("selected", "selected");});

This does the trick!


That’s a wrap

Without using heavy coding a power user can do many things on the SharePoint platform. You can extend your out of the box SharePoint with the help of using Jquery. On the internet you can find many resources with ‘ready to go’ Jquery scripts for your SharePoint platform and extend the SharePoint user experience. Be careful to test your code always in a test environment before putting it live on a production environment!

Monday, March 8, 2010

SharePoint 2010 & Office 2010 Launch may 12th

Microsoft has spread the news. The new SharePoint 2010 RTM and Office 2010 RTM will be released on may 12th. No more working on unsupported Beta 2 or RC's. Finally things will go through!

for more information, check the Microsoft SharePoint Team blog.