6/28/2010

SharePoint 2010: Color Coded Calendars!

An expanded version of this article, along with many other customization examples and how-tos can be found in my book, SharePoint 2007 and 2010 Customization for the Site Owner.

 

 

Updated 9/6/11

Service Pack 1 broke my color coded calendar code! For details see here. The code below has been updated to work with both the pre-SP 1 and SP 1 installations.

 

Updated 2/20/11

As I’m working on my customization book I am revisiting every one of my past “quick tips”. As I do so I am often finding a better way to do something. I ran into some issues working around the asynchronous loading of calendar events with the article below. After digging more into the code behind the calendar pages in 2010 I have found a much better way to trigger the color coding code.  The sections that have been replaced below are now crossed out (aaaaaa) and the new content added.

This update also solves most of the issues found in the comments at the end of this article, especially the “more items” problem.

 

 

Color Coded Events in SharePoint 2010 Calendars

Back in 2008 I wrote a little blog article on adding color to SharePoint 2007 calendar events. Several people have been pestering me to update it for SharePoint 2010, so here goes...

Several things have changed between SharePoint 2007 and 2010 to prevent the old example from working. For fellow “SharePoint client side hackers” I thought I would document the trail I followed to get color coding to work in 2010. For those who do not care about the details, just scroll on down to “Color Coded Events in SharePoint 2010 Calendars Step by Step”.

They broke the Content Editor Web Part!

In 2010 it’s now just called “Content Editor” and is in the “Media and Content” section of Add a Webpart:

image

 

When you add this web part you get a “wiki style” editor. Just click in the new web part and start typing. The Ribbon will then be updated to show all of the Rich Text editor options.

image

 

How do you add HTML?

You can just click the HTML button in the Ribbon (image ). But read on for some fun issues with this option…

image

But when you add CSS or JavaScript you may get this nice little message!

image

As a trivial example I entered:

  <style>
    .s4-titletext h1 a
    {
      color:red
    }
  </style>

and it reformatted it as:

  <style>

    .s4-titletext h1 a
    {
      color:red
    }</style>

and each time you go back into the HTML editor and click OK and adds another blank line after <STYLE>

  <style>

    .s4-titletext h1 a
    {
      color:red
    }</style>

It has even changed capitalization. In one of my edits it changed color:red  to  COLOR:red.

Who knows why….

 

So add your code directly to the page

Use SharePoint Designer and add the code to the bottom of the view page. The best place is most likely  between the “</WebPartPages:WebPartZone>” tag and the “</asp:Content>” tag. If you are using SharePoint Designer 2010 you will need to click “Advanced Mode” in the ribbon to edit that area.

 

Or just link to your code!

Both 2007 and 2010 offer the option to link from the CEWP to a text file with our content. So for 2010 I usually upload a text file containing the code to a library. Then in the CEWP just click the “Edit Web Part” option in the dropdown and add the link to the code file.

image

 

 

They broke the Calendar!

Not really, but is sure has changed. In 2007 the calendar was created entirely server side. The HTML sent to the browser was the final, ready to display HTML. All we needed to do was to write a little JavaScript and/or CSS to “customize” it.

Why it’s now a bit harder to code…

In 2010 the data for the calendar is now asynchronously loaded using a JavaScript function call after the page is loaded. That means that the data we want to change is not yet in the browser when our JavaScript is loaded from a Content Editor Web Part. If you have played with SharePoint client side JavaScript then you have seen the following command used to run a function after the page has loaded.

_spBodyOnLoadFunctionNames.push("_spAjaxOnLoadWaitWPQ2")

Note: _spBodyOnLoadFunctionNames is just a JavaScript array and push is a JavaScript method to add a new item to the end of the array. When a SharePoint page is loaded each function listed in this array is called in order.

I have used this often in 2007 to make sure the page is fully loaded before my JavaScript runs. The problem is where Microsoft loaded this for calendars in 2010… at the very end of the page. That means that when I use a Content Editor Web Part to add my JavaScript it will be in the “queue” before the JavaScript used to add the calendar events. So my challenge now is to get my code to run after the code that loads the calendar.

The work around?

The work around? We have to get our function added to _spBodyOnLoadFunctionNames after SharePoint's calendar update function. One way is to add our JavaScript in the master page and write the code so it only impacts calendars. But that’s a bad workaround. We would then have JavaScript that’s only needed for calendars added to every page.

So here’s another workaround… (Have a better idea? Let me know!)  Add a bit of JavaScript at the bottom of the master page that checks for an array of my functions that need to be run. If there’s no array, then do nothing…

  <script type="text/javascript">
    if (window.mikesCode)
    {
      for (var i=0;i<mikesCode.length;i++)
      { 
        _spBodyOnLoadFunctionNames.push(mikesCode[i]);
      }
    }
  </script>

Then in the Content Editor Web Parts (or anywhere else) add a custom function and add it to my little array.

  function DoSomethingCool()

  {

    // code here

  }

  if (!window.mikesCode)
  {
    mikesCode=new Array();  // create mikesCode if it does not exist
  }
  mikesCode[mikesCode.length] = "DoSomethingCool";   //add the function to run

 

Now we have all of the pieces…  (but I’m not finished with this article… I want to find a way to do this without the master page edit)

 

The new “work around!”

To get our code to run at the right time we need to hook into the SharePoint code that loads the calendar items. Once such place is a function named "SP.UI.ApplicationPages.CalendarNotify.$4a".We also need to delay the load of our code, and we can do that with a SharePoint feature named "_spBodyOnLoadFunctionNames.push".

As a result of this change I can now eliminate the need for the master page edit. (That trick is still useful for other kinds of customizations.)

 

 

Color Coded Events in SharePoint 2010 Calendars Step by Step

 

Add a little piece of code to the master page

  1. Open SharePoint Designer 2010 and open your site
     
  2. In the Navigation pane and in the Site Object section click Master Pages
     
  3. Click your master page (most likely “v4.master”) and if asked, check it out
     
  4. In Customization section click “Edit file”
     
  5. Scroll to the bottom of the file and just before the </body> tag add the script below
     
  6. Save the file and then check it in

<script type="text/javascript">
  if (window.mikesCode)
  {
    for (var i=0;i<mikesCode.length;i++)
    {
      _spBodyOnLoadFunctionNames.push(mikesCode[i]);
    }
  }
</script>

 

Setup the Calendar

The steps here are identical to the SP 2007 article.

  1. Create or open a calendar
     
  2. Add a new column named "Color" – most likely type will be "Choice" with choices like "Red, Green, Blue, Black", but this could be a lookup or a single line of text.
    (See here for an HTML color chart: http://www.w3schools.com/html/html_colornames.asp)
     
  3. Add a new column named "CalendarText"
    1. Column Type is Calculated
    2. Equation is:
          ="<font color='" & Color & "'>" & Title & "</font>"
      image
    3. Data type returned = single line of text
       
  4. Modify the existing view, or create a new view such as "Color Calendar"
     
  5. Change the field used for the Month View Title AND Day View Title AND Week View Title to "CalendarText"
    image
     
  6. Save and exit (The HTML for "<FONT" will now be displayed. Some JavaScript will be needed to fix the HTML tags)

Create the JavaScript file

Two Solutions!

1) Add a Content Editor Web Part as we have done in many of the other customizations. The problem with this approach is that SharePoint 2010 will no longer treat this page as a view. When this page is displayed you will see two changes:

· The View dropdown list in the site title area is missing

· The Ribbon will not be displayed when the page is first loaded, but will be displayed when any event item is clicked.

2) Add the custom JavaScript using SharePoint Designer. The page will then display as an ordinary view no odd behavior.

I recommend #2.

 

Option #1: Using the Content Editor Web Part

I usually add a library named Scripts, ScriptFiles or similar for these kinds of files. The steps below will just use the Shared Documents library.

  1. Open Windows Notepad and add the script below
  2. Save the file with a name like “CalendarColorScript.txt”
  3. Upload the text file to your library (Shared Documents in this example)

<script type="text/javascript" language="javascript">

  function CalColor()
  {
    var x = document.getElementsByTagName("div")
    var i=0;
    for (i=0;i<x.length;i++)
    {
      if (x[i].className=="ms-acal-item")
      {
        x[i].innerHTML= x[i].innerHTML.replace(/&lt;/g,'<').replace(/&gt;/g,'>')
      }
    }
  }

  // hook into the SharePoint JS library to call our code
  // whenever the calendar is updated
  function CalHookIntoSPUI()
  {
    var originalCalendarNotify = SP.UI.ApplicationPages.CalendarNotify.$4a;
    //var originalresetSelection = SP.UI.ApplicationPages.CalendarViewBase.prototype.resetSelection;

    SP.UI.ApplicationPages.CalendarNotify.$4a = function()
    {
      originalCalendarNotify();
      CalColor();
    }
  }

  // add to the array of functions to run from the master page code
  if (!window.mikesCode)
  {
    mikesCode=new Array();
  }
  mikesCode[mikesCode.length] = "CalColor";
  mikesCode[mikesCode.length] = "CalHookIntoSPUI";

</script>

 

(updated 9/6/2011)

<script>
// Color coded calendars for SharePoint 2010
// TechTrainingNotes.blogspot.com

// load our function to the delayed load list
_spBodyOnLoadFunctionNames.push('colorCalendarEventLinkIntercept');

// hook into the existing SharePoint calendar load function
function colorCalendarEventLinkIntercept()
{

  if (SP.UI.ApplicationPages.CalendarNotify.$4a)
  {
    var OldCalendarNotify = 

SP.UI.ApplicationPages.CalendarNotify.$4a;
    SP.UI.ApplicationPages.CalendarNotify.$4a = function () 
      {
        OldCalendarNotify();
        colorCalendarEventLinks();
      }
  }
  if (SP.UI.ApplicationPages.CalendarNotify.$4b)
  {
    var OldCalendarNotify = 

SP.UI.ApplicationPages.CalendarNotify.$4b;
    SP.UI.ApplicationPages.CalendarNotify.$4b = function () 
      {
        OldCalendarNotify();
        colorCalendarEventLinks();
      }
  }
  // future service pack change may go here!
  // if (SP.UI.ApplicationPages.CalendarNotify.???)

}

// hide the hyperlinks
function colorCalendarEventLinks()
{

  // find all DIVs
  var divs = document.getElementsByTagName("DIV");
  for (var i=0;i<divs.length;i++)
  {
    // find calendar item DIVs
    if (divs[i].className.toLowerCase()=="ms-acal-item")
    {
divs[i].innerHTML = divs[i].innerHTML.replace(/&lt;/g,'<').replace(/&gt;/g,'>');
    }

    // find "x more items" links and re-remove links on Expand/Contract
    if (divs[i].className.toLowerCase()=="ms-acal-ctrlitem")
    {
      var links = divs[i].getElementsByTagName("A");
      if (links.length==1)
      {
        links[0].href="javascript:colorCalendarEventLinks();void(0);"
      }
    }

  }
}

</script>

 

Add a Content Editor Web Part to hold the JavaScript

  1. Go to the document library where you uploaded the script file, right-click the file name and select Properties
     
  2. Copy the URL to the file and click OK
     
  3. Display your calendar and select the view you modified earlier
     
  4. Click Site Actions and then Edit Page
     
  5. Click “Add a Web Part” and select the Content Editor web part
    image
     
  6. In the new web part’s dropdown menu click “Edit Web Part”
    image
     
  7. Paste in the URL to the script file you copied in step 2
     
  8. Click OK
     
  9. In the Ribbon click “Stop Editing” (in the Page tab)

 

Option #2 Using SharePoint Designer

This is the preferred method as it does not break view related functionality as does adding a web part.

  1. Go to the calendar in the browser and create a new view (maybe "Calendar - No Links")
     
  2. Open your site in SharePoint Designer 2010
     
  3. Click Lists and Libraries in the Site Objects pane
     
  4. Click your calendar list and click the new view
     
  5. In the ribbon click the "Advanced Mode" link (so you can edit the entire page)
     
  6. Search for "</WebPartPages:WebPartZone>" and insert a new line just after this tag
    </WebPartPages:WebPartZone>
      your customization goes here (don't type this J )
    </asp:Content>
     
  7. Add the JavaScript from below
     
  8. Save your changes in SharePoint Designer
     
  9. Go to the calendar, add a new event and select a color, and see if the colors are displayed.

 

Everything (or at least option #1) comes with a price   :-(

The above works! But… you lose one feature. When you add a web part to a view you lose the ability to select a view from the crumb trail. (This is not a problem if you add the code using SharePoint Designer)

Without a web part on the page:

image

 

With a web part on the page:  (this is our “Color Calendar” view)

image

 

Notice that the crumb trail now only has the list name. The view name is missing. When the view name is displayed then you also have the dropdown to select other views

You can still switch views, but you must first click in the calendar to display the ribbon.

Bug?  Probably.  (So use option #2 – add the code with SharePoint Designer)

 

Some thoughts on color options…

Just change the FONT tag to a SPAN tag and use a style. Example:

    ="<span style='background-color:"&Color&"'>"&Title&"</span>"

This works, but the background is for just the width of the text, not the entire table cell.

You will probably want to use colors like lightblue, lightgreen, tomoto (light red would just be Pink!), etc. or make the text white or a light color:

    ="<span style='color:white;background-color:"&Color&"'>"&Title&"</span>"

image

 

Closing Notes

  • Document everything, and add to your disaster recovery plan (otherwise you’ll never remember how you did this,and consider the poor person who inherits this site from you)
     
  • In researching the SP.UI.ApplicationPages.CalendarNotify update I found a blog article by Mark Wilson that also intercepted the SP.UI.ApplicationPages.CalendarViewBase.prototype.resetSelection function. My code seems to work fine without it. But in any case go take a look at Mark’s article to see another approach to color coded calendars.
     
  • This has been tested only with IE 8 and FF 3.5.9 so far.
     
  • Batteries not included, your mileage may vary, please test, test, test…

.

6/20/2010

Live Chats to Learn more about SharePoint - with 17 MVP Experts

 

 

Do you have questions about SharePoint?


Do you have questions about SharePoint? Want to learn more about the recently launched SharePoint 2010? By popular request, SharePoint MVPs from around the world are participating in a live chat event about SharePoint. These Q&A events are a great opportunity to tap into the vast knowledge of these industry professionals who are regarded as the best in their field.

Please join us on Wednesday June 23rd at 9am PDT! (12 noon EST) Learn more and add these chats to your calendar by visiting the MSDN event page http://msdn.microsoft.com/en-us/chats/default.aspx

 

On June 23rd, tune in between 9:00 - 10:00 AM Pacific time (12-1pm EST) to chat with the following MVPs:

1. Amanda Perran
2. Ben Curry
1. Bryan Phillips
4. Dan Attis
5. Daniel Larson
6. Jason Medero
7. Mike Oryszak
8. Muhanad Omar
9. Paul Schaeflein
10. Paul Stork
11. Randy Drisgill
12. Rob Foster
13. Saifullah Shafiq Ahmed
14. Serge Tremblay
15. Shane Perran
16. Spencer Harbar
17. Woody Windischman

 

Nope… I won’t be there!  :-(                I’ll be in class…  :-)

.

6/13/2010

OWA and the Twilight Zone?

 

I know I’m putting in too many hours and losing track of time, but either OWA (or FireFox) has lost it’s mind, or I have slipped off to the Twilight Zone…

 

I went to my calendar to check my class schedule, switched to Day view and got this:

             image

June has been tough, with 4 beta exams, classes and everything else, but that is a bit ridiculous! Three day weeks look good to me, but six week months will be a problem.

 

Then I heard about SharePoint Conference 2011 and decided to add that to my schedule…

            image

OWA thinks that 10/6/2011 is Thursday in the dropdown, but also Sunday in the popup calendar!  And… now there’s only six days in a week!

This is only a problem with FireFox (3.5.9). The calendars display fine with IE 7.   But. this just started this week!

 

So I think I’ll just get an ice tea and head out to the deck for a while…

 

.

6/11/2010

Planning WAY Ahead… Tech-Ed 2011!

Tech-Ed 2010 is over today… and I missed out this year  :-(

But,

Tech-Ed 2011 has been scheduled!

May 16-19 2011  in  Atlanta

 

Sign up for EARLY discounts by June 30th, 2010

http://northamerica.msteched.com/registration

 

Home page: http://northamerica.msteched.com

 

See you there!

 

.

6/10/2010

Planning WAY Ahead… SharePoint Conference 2011

 

SharePoint Conference 2011

 

It’s June 2010 and Microsoft SharePoint Team is announcing SharePoint Conference 2011:

http://blogs.msdn.com/b/sharepoint/archive/2010/06/08/save-the-date-sharepoint-conference-2011.aspx

(Maybe it’s a way of saying… no SharePoint Conference 2010!)

 

The conference site is already online!  http://www.mssharepointconference.com/Pages/default.aspx

But you can’t register until the spring of 2011…

 

SharePoint Conference 2011 – October 3-6 2011 - Anaheim, California

 

This is so far in the future… that Outlook OWA is even confused.  It thinks that 10/6/11 is Thursday in the dropdown, but also Sunday in the popup calendar!  (See… I’ve put in my calendar, so should you!)

 

image

 

.

6/04/2010

TechTrainingNotes now twittering…

 

I’ve been pestered about not being up to date and “twittering”. Well, I’m not twittering, but my blog site is…

 

My blog is on blogspot.com and they have added a feature to “twitter” new blog articles.

 

So…

Follow TechTrainNotes on Twitter

 

 

 

 

You can of course still use an RSS feed:   image  http://feeds2.feedburner.com/TechTrainingNotes

.

5/29/2010

SharePoint: Rotating Pictures, Random Pictures (yet again!)

 

This little Content Editor Web Part trick has turned out to be pretty popular. Too popular… it has generated a lot of requests for “could also add…”.  So here are two of those, navigation buttons, and caption text.

 

image

 

First go the original article and read about how this all works:
   http://techtrainingnotes.blogspot.com/2009/07/sharepoint-rotating-pictures-random.html

 

What’s been added:

  • Two new options:
    • manualClick – set this to true to display the First, Previous, Play, Next and Last buttons
    • customTextColumn – set this to true to add a “caption” or custom text

What else you will need/want to do:

  • Customize the HTML at the end of the code. My example puts the picture on the left and the text on the right and left aligns the buttons
  • Replace the navigation hyperlinks with real buttons or images

Now the revised steps to setup this up:

  • Create your picture library and upload your pictures
     
  • If you would like to supply text/captions for the pictures, add a “Single line of text” or “Multiple lines of text” column 
     
  • If you would like to filter the list of pictures to be displayed, customize the library to add additional columns to how the filter data. (Event name, department, product, etc)
     
  • Go to your web part page and add the web part for the new library
     
  • Important steps:
    • Click Edit, Modify Shared Web Part
    • Optional: In the appearance section give the web part a meaningful name
    • Click Edit the Current View
    • Un-checkmark all of the columns except for “Name (linked to document)”
    • Checkmark a column to use for the custom URL (if you don’t have a custom URL then select any column)   (this must be the second column in the view)
    • Checkmark a column to use as a custom text/caption (this must be the third column in the view)
    • Optional: Set the sort order
    • Optional: Set filter options to select only the pictures you want displayed
    • Make sure the the list web part view is not using a "Item Limit" less then the number of pictures in the list. (You could just set this to be BIG number).
    • Click OK to save the view changes
    • Click OK to save the web part changes
       
  • Add a Content Editor Web Part (CEWP) below the picture library web part
     
  • Click Edit, Modify Shared Web Part
     
  • Click Source Editor
     
  • Copy and paste the code from below
  • Edit the “vars” at the beginning of the JavaScript
    • pictureWebPartName – enter the web part, and if your library has a description, then include it:
         Example: Library name: “Airshow Pictures”
                 var pictureWebPartName="Airshow Pictures
         Example: Library name: “Airshow Pictures”,  description: “Pictures from the Dayton Airshow” 
                 var pictureWebPartName="Airshow Pictures -  Pictures from the Dayton Airshow”
       
    • Also edit showThumbnails, randomImg, useCustomLinks, RotatingPicturesLoopTime, imgToImgTransition, manualClick and customTextColumn as needed
       
  • Click OK for the Source Editor
     
  • Click OK to save the web part changes
     
  • Click Exit Edit Mode and see if it works!
     

The Code

<script>
// another CEWP trick from http://techtrainingnotes.blogspot.com
var pictureWebPartName="Airshow Pictures - Pictures from the Dayton Airshow"; // name of the picture library web part
var showThumbnails = true;      //otherwise show full sized images
var randomImg = true;           //set to true to show in random order
var useCustomLinks = true;     //true to use second column as URL for picture clicks
var RotatingPicturesLoopTime = 5000;  //2000 = 2 seconds
var imgToImgTransition = 1.0;         //2 = 2 seconds  
var manualClick = true;         //true to use the play pause buttons
var customTextColumn = true;    //true to display text / caption

// don't change these
var selectedImg = 0;
var imgCache = [];
var imgTag;

function RotatingPictures()
{

  if (manualClick) {buttonRow.style.display="inline"};
  if (customTextColumn == "") {customTextTD.style.display="none"}

  imgTag = document.getElementById("RotatingImage");
  //Find the picture web part and hide it
  var Imgs = [];
  var x = document.getElementsByTagName("TD"); // find all of the table cells
  var LinkList;
  var i=0;

  for (i=0;i<x.length;i++) 
  {
    if (x[i].title == pictureWebPartName)
    {
      // tables in tables in tables... ah SharePoint!
      LinkList = x[i].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
      // hide the links list web part
      LinkList.style.display="none"; 
      break;
    } 
  }

  if (!LinkList)
  {
    document.all("RotatingImageMsg").innerHTML="Web Part '" + pictureWebPartName + "' not found!";
  }

  //Copy all of the links from the web part to our array

  var links = LinkList.getElementsByTagName("TR") // find all of the rows
  var url;
  var len;
  for (i=0;i<links.length;i++) 
  {
    
    if (links[i].childNodes[0].className=="ms-vb2")
    {
      len=Imgs.length
      Imgs[len]=[]
      Imgs[len][0] = links[i].childNodes[0].childNodes[0].href;
      if (useCustomLinks)
      {
        if (links[i].childNodes[1].childNodes.length>0)
         { Imgs[len][1] = links[i].childNodes[1].childNodes[0].href; }
         else
         { Imgs[len][1] = "" }
      }
      if (customTextColumn)
      { 
        if (links[i].childNodes[1].childNodes.length>0)
         {Imgs[len][2] = links[i].childNodes[1].nextSibling.childNodes[0].innerHTML;}
         else
         {Imgs[len][2] = "" }      }
    }
  }
  if (Imgs.length==0)
  {
    document.all("RotatingImageMsg").innerHTML="No images found in web part '" + pictureWebPartName + "'!";
  }
  for (i = 0; i < Imgs.length; i++)
  {
    imgCache[i] = new Image();
    imgCache[i].src = Imgs[i][0];
    if (useCustomLinks)
    {
      imgCache[i].customlink=Imgs[i][1];
    }
    if (customTextColumn)
    {
      imgCache[i].customtext=Imgs[i][2];
    }

  }
  RotatingPicturesLoop();
}


// now show the pictures...
function RotatingPicturesLoop()
{
  if (!manualClick)
    if (randomImg)
    {
      selectedImg=Math.floor(Math.random()*imgCache.length);
    }

  if (document.all){
      imgTag.style.filter="blendTrans(duration=" + imgToImgTransition + ")";
      imgTag.filters.blendTrans.Apply();
  }

  url=imgCache[selectedImg].src
  if (useCustomLinks)
  { RotatingImageLnk.href=imgCache[selectedImg].customlink; } 
  else
  { RotatingImageLnk.href = url; }

  if (customTextColumn) 
     customTextTD.innerHTML = imgCache[selectedImg].customtext.replace(/&lt;/g,'<').replace(/&gt;/g,'>');
  else
     customTextTD.innerHTML = "";

  if (showThumbnails)
  {
    // convert URLs to point to the thumbnails...
    //   from  airshow%20pictures/helicopter.jpg
    //   to    airshow%20pictures/_t/helicopter_jpg.jpg

    url = revString(url);
    c = url.indexOf(".");
    url = url.substring(0,c) + "_" + url.substring(c+1,url.length);
    c = url.indexOf("/");
    url = url.substring(0,c) + "/t_" + url.substring(c,url.length);
    url = revString(url) + ".jpg";
  }


  imgTag.src = url;
  if (document.all){
    imgTag.filters.blendTrans.Play();
  }

  if (!manualClick)
  {
    selectedImg += 1;
    if (selectedImg > (imgCache.length-1)) selectedImg=0;

    setTimeout(RotatingPicturesLoop, RotatingPicturesLoopTime);
  }
}


// utility function revString found here:
// http://www.java2s.com/Code/JavaScript/Language-Basics/PlayingwithStrings.htm
function revString(str) { 
   var retStr = ""; 
   for (i=str.length - 1 ; i > - 1 ; i--){ 
      retStr += str.substr(i,1); 
   } 
   return retStr; 
}

function moveFirst() {manualClick = true; selectedImg = 0; RotatingPicturesLoop()}
function moveNext() {manualClick = true; selectedImg += 1; if (selectedImg > (imgCache.length-1)) selectedImg=0; RotatingPicturesLoop()}
function movePrev() {manualClick = true; selectedImg -= 1; if (selectedImg < 0 ) selectedImg=imgCache.length-1; RotatingPicturesLoop()}
function moveLast() {manualClick = true; selectedImg = imgCache.length-1;  RotatingPicturesLoop()}

function movePlay() {
  if (PlayButton.innerHTML=="Play") 
  {
    manualClick = false; 
    PlayButton.innerHTML="Pause"; 
  } 
  else
  {
    manualClick = true; 
    PlayButton.innerHTML="Play"; 
  }

RotatingPicturesLoop()}




// add our function to the SharePoint OnLoad event
_spBodyOnLoadFunctionNames.push("RotatingPictures"); 

</script>




<!-- add your own formatting here... -->
<center>
  <table border="0" cellpadding="0" cellspacing="0" width="100%">
    <tr>
      <td id="VU" height="125" width="160" align="center" valign="middle">
<a name="RotatingImageLnk" id="RotatingImageLnk" alt="click for larger picture">
        <img src="/_layouts/images/dot.gif" name="RotatingImage" id="RotatingImage" border=0>
</a>
        <span name="RotatingImageMsg" id="RotatingImageMsg"></span>
      </td>
      <td ID="customTextTD" name="customTextTD"  width="100%" style="padding: 4px 1ex 4px 4px;">
         <span name="RotatingImageText" id="RotatingImageText"></span>
      </td>
    </tr>
    <tr id="buttonRow" style="display:none"><td colspan="2" align="left">
      <a href="" onclick="moveFirst();return false;">First</a>
      <a href="" onclick="movePrev();return false;">Previous</a>
      <a href="" onclick="movePlay();return false;" name="PlayButton" ID="PlayButton">Play</a>
      <a href="" onclick="moveNext();return false;">Next</a>
      <a href="" onclick="moveLast();return false;">Last</a>
    </td></tr>
  </table>
</center>

 

 

 

.

5/27/2010

SharePoint 2010: Developer Dashboard Notes

 

If you have not seen the Developer Dashboard, then go GoogleBing it now. While working with it I found a few interesting issues… so what follows are miscellaneous notes that may help someone in the future.

The Dashboard is enabled using:

  • STSADM
  • PowerShell
  • or code

 

STSADM

STSADM is going away! PowerShell is the new admin tool… but that said, they did ship STSADM with SP 2010 and it can be used to enable the Developer Dashboard.

While the Dashboard can be enabled with STSADM, it is not listed in help! (“stsadm -help setproperty”  does not list it!)  So you will need to make note of the syntax or bookmark the TechNet page.  Speaking of which, I can’t find a page on TechNet or MSDN that officially documents this option. It does get mention in a few places, like here: http://msdn.microsoft.com/en-us/library/ff512745.aspx

Here’s what I can find:

   stsadm -o setproperty -pn developer-dashboard -pv on

   stsadm -o setproperty -pn developer-dashboard -pv off

   stsadm -o setproperty -pn developer-dashboard -pv ondemand

 

PowerShell

The “Official” example here shows this PowerShell example:

    (Get-SPFarm).PerformanceMonitor.DeveloperDashboardLevel = ”On”

Only thing is… it does not work.  (Maybe it worked in one of the betas)

Here is a good discussion about the feature, and how to create your own cmdlet for the Dashboard:
http://www.toddklindt.com/blog/Lists/Posts/Post.aspx?ID=189

 

Here’s the PowerShell command from that blog article:

$dash = [Microsoft.SharePoint.Administration.SPWebService]::ContentService.DeveloperDashboardSettings;

$dash.DisplayLevel = 'OnDemand';

$dash.TraceEnabled = $true;

$dash.Update()

 

(a lot to type, so create your own script or follow the blog article above to create a cmdlet)

Note: The SPWebService in the command above is not a “Web Services” reference. SPWebService is part of the hierarchy of SharePoint:   Farm –> Service –> Application –> Site Collection –> Web –> lists, etc.  SPWebService is one of many SharePoint “services”. SPWebService is responsible for the rendering of web pages.

 

Code

Here’s a C# example of turning the Dashboard on:

SPWebService ws = SPWebService.ContentService;
ws.DeveloperDashboardSettings.DisplayLevel = SPDeveloperDashboardLevel.OnDemand;
ws.DeveloperDashboardSettings.TraceEnabled = true;  //optional, but pretty cool (try it!)
ws.DeveloperDashboardSettings.Update();

 

DeveloperDashboardSettings

The DeveloperDashboardSettings is an interesting object. Here’s some of the methods and properties:

Methods:

  • DisableDiagnosticMode
  • EnableDiagnosticMode

Properties (and their defaults)

  • DisplayLevel                                  : Off
  • TraceEnabled                                : False
  • AutoLaunchEnabled                     :  False
  • RequiredPermissions                  : AddAndCustomizePages
  • MaximumSQLQueriesToTrack    : 50
  • MaximumCriticalEventsToTrack  : 50
  • AdditionalEventsToTrack              : {}

 

Instead of duplicating what someone else has done an excellent job of, I’ll list the few things above as a teaser and then refer you to this blog article by Geoff Varosky:
    http://gvaro.spaces.live.com/blog/cns!B06529FD3FC75473!928.entry?sa=54522551

 

.

 

Developer Dashboard Test 1

Developer Dashboard Test 2

Developer Dashboard Test 3

Developer Dashboard Test 4

Developer Dashboard Test 5

SharePoint 2010: Windows Explorer View is Gone!

Updated 8/5/10

 

Not new news, and for some people, “good riddance”, but as I had a question about it this week…

 

SharePoint 2010 has a replacement for the Windows Explorer View, and the old Upload Multiple (sort of… see “Mileage may vary” below) is also gone.  But drag and drop is not gone. Both options have both been replaced with a new Upload Multiple option that supports drag and drop from Windows Explorer into the browser.

Actually the Explorer View is still there, but you many not want to use it after you have seen the new “multiple upload”.  Here’s the new place to find Open with Explorer:

image

 

The Open with Explorer and the new Upload Multiple seems to depend on Office 2010 being installed. (For example, if you have Office 64 bit or Internet Explorer 64 bit, a number of Office integration options will not currently work.)

 

The new Upload Multiple

From a document library click the Documents tab, click the dropdown arrow next to “Upload Document” then click “Upload Multiple Documents”.  (or click Upload Document, then click Upload Multiple

   image 

 

A dialog box will open with a “drag area”.

image

Note: Prior to dragging files, the Cancel button cancels the dialog box. After you drop a file, the cancel button is grayed out. Going forward it is used to only cancel an upload in progress.  To close the dialog box you will need to click the “X”.

 

After displaying the above screen you can open a Windows Explorer and then drag files and folders to the browser. What’s interesting is that does not start the upload. It only displays a list of files and lets you remove any you don’t want to upload.

image

 

Then when you click OK it starts the upload with nice progress indicators.

image

 

 

If your library has folders, then the dialog will let you select a folder to upload to:

image

 

Microsoft did leave something behind that I did wanted changed… the default checked “Overwrite existing files”.  (Let me translate that as “Overwrite existing files” means “Overwrite files created by coworkers who have invested hours, days, weeks in other documents that just happen to have the same name are your documents and don’t warn me that I’m about to destroy them”.)  To see one way to fix that little problem see: http://techtrainingnotes.blogspot.com/2010/02/sharepoint-prevent-accidental.html

 

Your mileage my vary…

Or in other words… you may see something other than the above!

(For browser compatibility info see here: http://technet.microsoft.com/en-us/library/cc263526.aspx)

When using Firefox you may get this option when trying to get to Upload Multiple Documents:

image

The link above refers to a “Microsoft Office 2010 Firefox Plug-in", but I’ve not found it yet. All web searches for it return the same Microsoft link, or links with copies of that article. If you know where to find this, post a response to this blog and share!  I’ve heard that FireFox 4 might fix this… (now in beta)

 

Or from from IE 7… I’m not sure yet if this is because or IE 7 or because the machine it was running on (Vista and Office 2007).  This just happens to be the old 2007 upload multiple!

image

 

Can you still get to the Explorer View?

If you have Office or IE 64 bit installed you may not find the new multiple upload, or the link in the ribbon to the Windows Explorer View (image ).  You still may be able to get to the Windows Explorer view of SharePoint… Maybe… Open Windows Explorer from the desktop and enter a server style path to your library. It all depends on your network setup.

URL:  http://intranet/sites/demo/Shared%20Documents/Forms/AllItems.aspx

Path: \\intranet\sites\demo\Shared Documents

Basically, remove the “http:”, change all “/” to “\”, replace all escaped characters with their normal characters (“%20” for example, is a space) and remove references to ASPX pages.

URL:  http:  //intranet/sites/demo/ Shared%20Documents   /Forms/AllItems.aspx

Path:        \\intranet\sites\demo\ Shared Documents

 

image

 

.

5/25/2010

SharePoint 2010: Part 5: Preparing for 70-573 TS Microsoft SharePoint 2010, Application Development

(Start here: http://techtrainingnotes.blogspot.com/2010/05/sharepoint-2010-preparing-for-70-573-ts.html)

 

Wow! Workflows, custom SPD workflow actions, event receivers, timer jobs, BCS and ECM to boot… all in one section and it only represents 19% of the exam!  Sounds like it should be an exam all by itself.

(The workflow section refers to something called “inititation data” and “corelation tokens”, but I think I study up on “initiation data” and “correlation tokens”.)

 

Good news for experienced SharePoint 2007 developers… the core object model and techniques has not changed in these topics too much. But, there are new tools and a number of new features.  So don’t panic. Run though what you do know, but with Visual Studio 2010 (and the VS deploy wizards) and SP 2010, then take a look at what’s new, especially BDC.

 

Skills Being Measured:
Developing Business Logic (19%)

Implement a custom workflow in Visual Studio 2010

  • This objective may include but is not limited to: work with inititation data or association data to create a SharePoint task, extend a workflow imported from SharePoint Designer 2010, use a HandleExternalEvent and CallExternalMethod to interact with a custom local service, work with inititation data or association data in a site workflow, corelation token
  • This objective does not include: trivial cases such as workflows with no custom actions, initiation data, association data.

Create a custom workflow action

  • This objective may include but is not limited to: create a custom SPD action, create and add a custom activity to a Visual Studio workflow, define an action.xml file

Create and implement event receivers

  • This objective may include but is not limited to: accessing event properties, list, item, site, email, avoiding recursion, cancelling events, choosing synchronization state

Customize Enterprise Content Management (ECM)

  • This objective may include but is not limited to: creating a content type that inherit from appropriate parent, creating and implementing a custom publishing field control that is page mode aware, activating a master page programmatically including token usage
  • This objective does not include: page layouts, formatting

Create, implement and debug a Timer Job

  • This objective may include but is not limited to: configuration, programmatic scheduling, queuing, attaching debugger to the Timer service

Create and modify Business Connectivity Service model in Visual Studio 2010

  • This objective may include but is not limited to: create a BDC model in Visual Studio 2010, define insert, update and delete methods, create and read items, make data searchable

Manage Users, Groups, Permissions

  • This objective may include but is not limited to: SPGroups, SPUser, permission inheritance, all securable objects, SPRoleDefinition, SPRole, SPRoleAssignment

 

Notes:

 

Workflow

If you have not worked with SharePoint 3.0 workflows go and find any of the good books or online tutorials and videos.  Then start here: http://msdn.microsoft.com/en-us/library/ee537015.aspx

What’s new in 2010?

  • New activities/actions
  • Site workflows (in addition to list workflows)
  • New tools in Visual Studio 2010, including ASPX association and initiation forms
  • Import from SharePoint Designer 2010
  • Major changes in how SharePoint Designer creates workflows (the Skills Measured list does not include creating SPD workflows, but does include importing them, so you will need to know a little about creating them!)

So… here's the things you need to know (or at least my first guesses!) …

 

Custom workflow actions (for SPD):

  • Does not appear to have really changed from SP 2007
  • Create an activity for Visual Studio workflows, create a .actions file, then update web.config

Event receivers:

  • New places to use event handlers… see here and here
  • Largely the same as 2007
  • New templates/wizards in Visual Studio 2010

ECM, Content Types, custom publishing fields, master pages:

  • I think I got the master page topic covered in my prep in Part 4.
  • New templates/wizards in Visual Studio 2010

Timer jobs:

  • New ways to manage timer jobs in Central Administration and PowerShell
  • Know about scheduling and OWSTIMER.EXE

BCS:

  • BCS tools in Visual Studio
  • Now part of SharePoint Foundation (BDC was part of MOSS Enterprise)
  • Supports caching and offline
  • CRUD – Create, Read, Update, Delete
  • External lists
  • Now support BLOBs
  • SharePoint Designer support to create external lists
  • See the BCS Resource Center for lots of useful content, videos, articles

 

Users, Groups, Permissions:

  • Other than a small change to SPAlert (email vs SMS), the object model looks the same as for 2007.

 

Links:

Note: Many of these links include a link to the 2007 version of the documentation, so also check the 2007 version for “Community Comments”.

  • Workflows

MSDN: What's New: Workflow Enhancements
http://msdn.microsoft.com/en-us/library/ee537015.aspx

MSDN: Workflows in SharePoint Server 2010
http://msdn.microsoft.com/en-us/library/ms549489.aspx

MSDN: Workflow Development for SharePoint Foundation
http://msdn.microsoft.com/en-us/library/ms414613.aspx 

MSDN: Correlation Tokens in Workflows
http://msdn.microsoft.com/en-us/library/ms475438.aspx

  • Custom Workflow Actions

Make a Custom Activity available to SharePoint Designer 2010
http://www.chaholl.com/archive/2010/03/13/make-a-custom-activity-available-to-sharepoint-designer-2010.aspx

Walkthrough: Create a Custom Site Workflow Activity
http://msdn.microsoft.com/en-us/library/ee231574.aspx

  • Event Receivers

New Event Handlers in SharePoint 2010
http://philwicklund.com/archive/2009/10/20/new-event-handlers-in-sharepoint-2010.aspx

MSDN: Event Receiver Methods Compared: Windows SharePoint Services 3.0 and SharePoint Foundation 2010
http://msdn.microsoft.com/en-us/library/ff407299.aspx

How to: Create an Event Receiver
http://msdn.microsoft.com/en-us/library/ee231563.aspx

Example: Creating a List Item Event Handler
http://msdn.microsoft.com/en-us/library/ms437502.aspx

How to: Create an Event Receiver for a Specific List Instance
http://msdn.microsoft.com/en-us/library/ff398052.aspx

  • Timer Jobs

Creating Custom Timer Jobs in Windows SharePoint Services 3.0
(2007) http://msdn.microsoft.com/en-us/library/cc406686%28office.12%29.aspx

  • BCS

MSDN: Microsoft Business Connectivity Services
http://msdn.microsoft.com/en-us/library/ee556826.aspx

Sharepoint 2010 BCS new features
http://mikeren.wordpress.com/2010/03/22/sharepoint-2010-bcs-new-features/

First steps on the SharePoint 2010 BCS path
http://bloggingabout.net/blogs/jpsmit/archive/2010/02/12/first-steps-on-the-sharepoint-2010-bcs-path.aspx

Using Business Connectivity Services(BCS) In SharePoint 2010 For Connecting To MS CRM 4.0
http://malikhan.wordpress.com/2010/01/24/using-business-connectivity-servicesbcs-in-sharepoint-2010-for-connecting-to-ms-crm-4-0/

SP 2010: Getting started with Business Connectivity Services (BCS) in SharePoint 2010
http://www.zimmergren.net/archive/2010/01/18/sp-2010-getting-started-with-business-connectivity-services-bcs-in-sharepoint-2010.aspx

MSDN: BCS Resource Center | SharePoint 2010
http://msdn.microsoft.com/en-us/sharepoint/ff660755.aspx

  • Manage Users, Groups, Permissions

Overview of SharePoint security and securable objects: Plan site permissions (SharePoint Server 2010)
http://technet.microsoft.com/en-us/library/cc262778.aspx

Overview of SharePoint security and securable objects: Plan site permissions (SharePoint Foundation 2010)
http://technet.microsoft.com/en-us/library/cc287752.aspx


How-to’s, Tutorials, etc.

 

HOL07 - Developing a SharePoint 2010 Workflow with Initiation Form in Visual Studio 2010
http://www.microsoft.com/downloads/details.aspx?FamilyID=c010fc68-b47f-4db6-b8a8-ad4ba33a35c5&displaylang=en

Module 7: Developing Business Processes with SharePoint 2010 Workflows
http://msdn.microsoft.com/en-us/sharepoint/ee513154.aspx

Overview: Creating Workflows with SharePoint Designer 2010, InfoPath 2010 and Visio 2010
http://channel9.msdn.com/posts/matthijs/Overview-Creating-Workflows-with-SharePoint-Designer-2010-InfoPath-2010-and-Visio-2010/

Integrating SharePoint 2010 Workflows into Backend Systems Using External Data Exchange Services
http://channel9.msdn.com/posts/matthijs/Integrating-SharePoint-2010-Workflows-into-Backend-Systems-Using-External-Data-Exchange-Services/ 

 

Video: How Do I: Create Event Receivers for SharePoint 2010 in Visual Studio 2010?
http://msdn.microsoft.com/en-us/vcsharp/ff623003.aspx

 

 

.

Note to spammers!

Spammers, don't waste your time... all posts are moderated. If your comment includes unrelated links, is advertising, or just pure spam, it will never be seen.