SharePoint 2010: How check if a folder exists

In SharePoint client object model, I needed to check if a folder exists.
In the post How to check if folder subfolder already exists in SharePoint document library using SharePoint web service I have found the (almost) correct query to be used. It is missing and close and open <Eq> tag.

The correct version is:
<Query><Where>
<And>
<Eq>
<FieldRef Name='FileLeafRef' />
<Value Type='Text'>[your Folder name]</Value>
</Eq>
<Eq>
<FieldRef Name='FSObjType'/>
<Value Type='Text'>1</Value>
</Eq>
</And>
</Where></Query>

SharePoint: integrate the Lync presence control in your pages and web parts

For one organizational chart page I needed to incorporate the Lync presence control next to each name. Practically I wanted to replicate what you get when you show a list containing a people picker field, but without using a field of this type.

 

I have found the article Integrate Lync into your intranet sites using the NameCtrl plug-in.

Only a few notes on the article:

  • 'case' is a JavaScript keyword, so when it is used as a field in the DIV, it has to be enclosed between quotes;
  • when creating the id of the control, in the getId function, it's needed to use a replaceAll function for SIDs like name.surname@domain.com

SharePoint and JavaScript CSOM

I'm relizing that I'm spending too much time googling the same topics over and over (on JavaScript programming), so I list here a few solution I need in a recurrent way.

 

JavaScript: how understand if page is opened in iFrame, and get its url

 

Javascript: how get url parameters

  • function to get query string parameters:
    function getURLParameter(name) {
    return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||null
    }
  • source: How to get URL parameters with Javascript?

 

Javascript: function to format numbers

 

Javascript: function to format date-times

 

Javascript: how html encode strings

 

jQuery: how write a custom filter method

SharePoint: how add submenus in the top link bar

In SharePoint, without the Publishing Feature enabled, it's not possible to add sub-menus in the top link bar (except for sub-sites and related pages).

This is quite limiting, because it doesn't allow to organize menus in sites with many pages.

Luckily, I have found the solution in the article How can I add a dropdown menu to the Sharepoint Foundation top navigation bar?

Essentially, it's enough to import the file spf-dropdown2010.js or spf-dropdown2013.js after jQuery.

 

I have tried the solution above, and it worked, but it had the following:

  • PRO: possibility for the user to customize the sub-menus via SharePoint UI
  • CON: each time the page is loaded, the sub-menu items are seen for a short time
  • CON: for internal pages without the script, the sub-menus are not generated and so this doesn't give a nice UI (this point is valid in case it's not possible to modify the master page)

 

So I have changed implementation of the solution with the code below:

   $("span.menu-item-text:contains('TopMenu1')")

      .closest('li.static')

      .addClass('dynamic-children')

      .append('<UL class=dynamic></UL>')

      .find('ul')

      .append('<LI class="spfDropdowns-submenuitem dynamic"><A class="menu-item dynamic" href="Url1"><SPAN class=additional-background><SPAN class=menu-item-text>Descr1</SPAN></SPAN></A></LI>')

      .append('<LI class="spfDropdowns-submenuitem dynamic"><A class="menu-item dynamic" href="Url2"><SPAN class=additional-background><SPAN class=menu-item-text>Descr2</SPAN></SPAN></A></LI>');

SharePoint: grouping items into folders

For a project I had to create view and group list items based on the folders they reside.

Short answer: in SharePoint you can't group by folder (name).

So you have to map the folder information into some column associated to your data:

  • create a text / choice column to store the folder name
    if you have deeper levels, you can consider create a taxonomy column
  • map the folder to the newly created column via folder default values or eventually workflow (more extensible but slower)

 

An article explaining the concept using folder default values is Group Items on Their Folder Name Inside a SharePoint Library. This article also remembers that SharePoint folder default values don't exist in SharePoint 2007 and SharePoint 2010 Foundation.

SharePoint: how quickly empty the Recycle Bin

For my current project I have done a lot of tests, so my site Recycle Bin is really full.

Instead of emptying each page manually, I searched for a quicker options, and I have found that simply pasting javascript:emptyItems() on the address bar effectiverly clears it!

Only two notes:

  • when pasting, for security reasons Internet Explorer removes the javascript: from the address, so you need to write it manually;
  • if the operation goes in timeout because of a very big Trash Bin, simply re-try.

 

I have found this trick in the page Completely Empty the SharePoint Recycle Bin.