Posts Tagged ‘SPF 2010’

Useful JavaScript Function – Refreshing a page with parameters for use with Query String Filter Web Parts in #SP2010 #SharePoint #ProjectServer #PS2010 #in

February 22, 2011 Leave a comment

In my current project I have the need to determine the current users personal preferences based on favourites stored in a list.

These personal preferences then drive various web parts on the page.

Using this the Enterprise Edition of SharePoint Server 2010 makes this very easy with the use of the Query String Filter Web Part and various other web parts that support connections including:

  • Reporting Services Web Part
  • Excel Services Web Part
  • List Web Parts
  • etc…

Using the combination of parameters and the above web parts it makes it a lot easier to create dashboard pages that are specific to a users:

  • Preferences
  • Job Role
  • Department
  • etc…

Now in most of my projects, I have found that dashboard pages tend to be buried under a 2nd or 3rd level of navigation, which makes it very easy to create links with parameters already in them.

However, in this case, I have to create various dashboard pages at the root of the site, whilst using standard SharePoint Publishing Navigation (Global Navigation).  The parameters being passed are user selectable based on favourites stored in a list.

Given that the SharePoint Site Map Provider doesn’t know about this random favourites list I have created, I need to improvise to ensure that the end user is presented with dashboard pages personalised to them, as soon as they hit the root site URL.

Code Example:

1 <script type="text/javascript"> 2 3 var currentLocation = location.href; //Current Page URL 4 //set it to lowercase for comparison purposes 5 currentLocation = currentLocation.toLowerCase(); 6 7 //run function before document / SharePoint ready to avoid unwanted page flashing 8 refreshPageWithParameters(); 9 10 function refreshPageWithParameter() { 11 12 var urlParameter = ""; 13 14 //In this example I am checking for a query string parameter called portfolioid 15 urlParameter = querySt("portfolioid"); 16 17 //confirm we do not have the parameter so the page refresh doesn't loop 18 if (urlParameter == "") { 19 //Stop the rest of the page render, JavaScript will still run 20 document.execCommand("stop"); 21 22 /* 23 Run functions you need to do to get your parameter value here 24 25 set output of functions to urlParameter below 26 */ 27 28 urlParameter = "test"; //<function output here>; 29 30 var newURL = currentLocation; 31 32 if (currentPathname.indexOf("?") != -1) { 33 //& - Other Query String Parameters exist - add this to the end 34 newURL = "&portfolioid=" + urlParameter; 35 } 36 else { 37 //? - Other Query String Parameters do not exist 38 newURL = "?portfolioid=" + urlParameter; 39 } 40 41 //Refresh the page with the new URL 42 location.href = newURL; 43 44 } 45 46 } 47 48 function querySt(ji) { 49 50 //This Useful JavaScript function was explained in a previous blog post 51 hu =; 52 hu = hu.toLowerCase(); 53 gy = hu.split("&"); 54 55 for (i=0;i<gy.length;i++) { 56 ft = gy[i].split("="); 57 if (ft[0] == ji) { 58 return ft[1]; 59 } 60 } 61 62 return ""; 63 } 64 65 </script>

Essentially the following happens:

  • The page load to a certain point
  • We determine if we have the query string parameter(s) we are looking for
  • If we don’t, we stop the page from rendering using document.execCommand(“stop”)
  • Go get our require parameter(s)
  • Determine if any previous parameters existed on the page currently (to make the code more generic)
  • Reload the page with the new parameter(s)

If you find any unwanted page flashing before the page reload, use JavaScript to set style=”display: none;” on the main content <div> on the v4.master – Master Page, if the parameter doesn’t exist.

Although this is certainly one method of achieving my goal and seems to currently fit my clients requirements, I would certainly be interested to hear from others on how to achieve my goal without drastically changing standard SharePoint components.


Useful JavaScript Function: isInteger and isNumeric #SharePoint #SP2010 #in

February 16, 2011 Leave a comment

Just a quick post as a reminder for myself in future projects.

1 function isNumeric(sText) 2 { 3 var ValidChars = "0123456789."; 4 var IsNumber=true; 5 var Char; 6 7 8 for (i = 0; i < sText.length && IsNumber == true; i++) 9 { 10 Char = sText.charAt(i); 11 if (ValidChars.indexOf(Char) == -1) 12 { 13 IsNumber = false; 14 } 15 } 16 return IsNumber; 17 18 } 19 20 function isInteger(sText) 21 { 22 var ValidChars = "0123456789"; 23 var IsNumber=true; 24 var Char; 25 26 27 for (i = 0; i < sText.length && IsNumber == true; i++) 28 { 29 Char = sText.charAt(i); 30 if (ValidChars.indexOf(Char) == -1) 31 { 32 IsNumber = false; 33 } 34 } 35 return IsNumber; 36 37 } 38

Programmatically setting a field to hidden within a Content Type #SharePoint #SP2010 #in

February 9, 2011 2 comments

At a client recently, my development colleague was struggling to find out how to set a field attached to a custom Content Type in a list to be hidden to aid in document management (so it is not shown in the Document Properties panel in Microsoft Word).

The following post seemed to suggest an unofficial way:

However, we try to keep things in a supported model if possible.

Through further looking he came across the following property:

    After further playing in code, he managed to crack it with the “.hidden” method.
    Code Example:

This code will set the Hidden flag (same as you can through the UI) against the document library. The above iterates through a List of strings which contains the fields i want to hide.

    1 SPContentType docCT = docLib.ContentTypes[0]; 2 3 foreach (string fieldDispName in fieldsToHide) 4 { 5 SPField field = docCT.Fields[fieldDispName]; 6 docCT.FieldLinks[field.Id].Hidden = true; 7 } 8 9 docCT.Update(); 10

NB: Please not that this works because we are using our own content type attached to the library.

Creating Test / Filler / Example text from Microsoft Word #SharePoint #SP2010 #in ‘#MSOffice

February 7, 2011 1 comment

I always forget the following link when I want some example text in my projects for Plain / Rich Text fields (in Lists and InfoPath Forms), Word Documents (Document Management etc.)

Microsoft Office Help Link:

Quick Reference

Within Word type the following:

  • =rand()
  • =lorem()

These produce a single paragraph, but the function is configurable via the following parameters:

  • =rand(insert the number of paragraphs, insert the number of sentences)
  • =lorem(insert the number of paragraphs, insert the number of sentences)

Example: =lorem(1,6)

A reference / links to Creating Custom Actions in #SharePoint #SP2010 #in

February 7, 2011 Leave a comment

Some good links that a colleague found about adding custom menu actions (ECB):

SharePoint 2007 Examples:

SP2010 MSDN Article:

WSS 3.0 / MOSS 2007 MSDN Article:

Useful Information: Determining if the web service return is a File or a Folder in GetListItems (Lists.asmx) #in #SP2010 #SharePoint

February 7, 2011 Leave a comment

Just a useful quick tip I noticed whilst answering a question for a client the other day.

In the return of the GetListItems method of the Lists.asmx Web Service, one of the fields is:

  • ows_FSObjType

This essentially allows us to determine of the return is either a File or a Folder.

The detail of the return is as follows:

  • <Item ID>;#<File System Object Type>
  • Example Data: 1;#0

Options for the File System Object Type:

  • 0 = File
  • 1 = Folder

Useful JavaScript Function: PreSaveAction #SP2010 #SharePoint #PS2010 #ProjectServer #in

January 25, 2011 1 comment

Just a quick blog post to talk about a standard JavaScript function that exists in SharePoint 2007 and 2010 – PreSaveAction().

Now I have done extra validation and functions on list forms in allsorts of ways before (some of which is blogged on this site) and it is only recently that this standard function has been brought to my attention. (Thanks @GlynClough via twitter).

Once I learned about this function I of course google’d about it to see what I could find and came across the following blog articles:

These are excellent articles that explain the function, however in the way I tend to work in my projects it posed a problem.

We are essentially overriding a standard SharePoint JavaScript function and the articles assume that you can place a Content Editor Web Part onto the page to add the functionality.

Now in SharePoint 2010 this is less of a problem, since there are very good and official ways to add web parts to list form pages, even in a Publishing Site.

However, in Microsoft Office SharePoint Server 2007 utilising publishing sites, editing newform.aspx and editform.aspx pages caused many issues.

This forced the consultant / developer to create their own new / edit forms and pages in order to insert sometimes a very small amount of code.

Since most of my projects seem to involve the Publishing feature in one way or another, I typically place JavaScript reference files in the Master Page.  This means that my JavaScript code is running on every page.

So, getting to the point of this article, I have modified the general example that is supplied on other sites to take into account this method of JavaScript development by simply querying what page I am on before I run my validation tests and functions.

Code Example:

1 <script type='text/javascript'> 2 3 //global variable to be used in multiple functions 4 var currentPathname = location.pathname; 5 //set to lowercase to make comparisons in the code easier 6 currentPathname = currentPathname.toLowerCase(); 7 8 function PreSaveAction() {; 9 10 if (currentPathname.indexOf('Enter Pathname here IE. /lists/tasks/editform.aspx') != -1) { 11 //Setup your validation checks here 12 if (1 == 1) { 13 alert('Validation passed, let SharePoint continue'); 14 return true; 15 } 16 else { 17 alert('Validation failed, stop SharePoint from saving the item'); 18 return false; 19 } 20 } 21 22 //If we have got to this point, then no pages need pre-validation. Let SharePoint continue. 23 return true; // OK to proceed with the save item 24 } 25 26 </script>

I just won a free MSDN subscription… SharePoint Home Drive Web Part #in #SP2010 #SharePoint

December 1, 2010 10 comments

A while ago I entered a competition that Liam Cleary (MVP) was running about Web Part contributions in the community. (Link)

Turns out I won. (Link) Smile

Thanks Liam, I shall be using the subscription for some new web part ideas I have.

The web part in question was my SharePoint Home Drive web part.  This was developed for IT Administrators in schools to give access to Teacher’s & Student’s home drives within their intranet to aid SharePoint adoption.

It was released a couple of years ago and has been used in various educational institutions.  It has also recently been tested in SharePoint 2010.

Competition Entry:

1. What the original problem was

Ensuring that users can access their home drives within SharePoint to aid adoption of the SharePoint Portal within the education establishment.

2. Why SharePoint was chosen

SharePoint was chosen due to its flexibility and support from third party vendors for the various applications currently in use.

SharePoint’s educational licensing costs allows schools to user enterprise scale solutions for a fraction of the cost.

3. What the solution was (end-to-end)

To aid education establishments in providing a single collaboration portal connecting all appropriate solutions into one place including:

  • File Shares
  • Email
  • Cashless Catering
  • MIS integration
  • E-Learning
  • + others

4. How it helped

Although all the 3rd party vendors provided web parts etc. for the various applications, users were still having to go away from the solution to access their personal files.

Document libraries will be used for future years of children as the architecture catches up with the change in solution, however for current student data, financials did not allow for the required increase in storage in the SQL database.

Training of document libraries for non-IT staff in terms of uploading files and the understanding of metadata was troublesome and take up of the collaboration solution was slow among some staff and students.

Shared folders on the network were easily integrated using the Page Viewer Web Part in File / Folder mode and a Search Server Content Source of the Network Share.

However, this method could not easily be implemented for a user’s home drive, due to the dynamic nature of the UNC path.

Typically, this is set up in Active Directory using the user’s ADUserName (SAMAccountName) as the folder name for the share.

To solve this, I created a Web Part that allows administrators to specify the UNC path of the file share; it will then inject the AD username after the UNC path.

This provides a File Explorer view of the user’s home drive within the SharePoint Portal.

This was developed to be an interim solution until Document Libraries were fully adopted by end users and the SQL storage could be bought with future budget.

The SharePoint Home Drive web part was released to the community via CodePlex in June 2009 and has recently been tested in SharePoint 2010 environments also.

Compatibility of the Web Part also includes WSS 3.0 and SharePoint Foundation 2010.

Web Part URL:

Video Showcase – Media Player #in #SP2010

November 4, 2010 5 comments

SharePoint Media Player 1.1

A web part which places a Windows Media Player object on the page to play audio / video. The web part takes into account the problem of menu’s going behind the Media Player window.


  • Windows SharePoint Services 3.0
  • Microsoft Office SharePoint Server 2007
  • SharePoint Foundation 2010
  • SharePoint Server 2010
%d bloggers like this: