March 2010 - Posts

Earlier this week at the Mix10 conference, Microsoft announced the developer story of the Windows Phone 7 Series. As expected, it’s all about Silverlight! For all the details I highly recommend to watch the recorded keynotes (day 1, day 2).

Tonight I could resist trying to build my very first Windows Phone 7 application; the traditional Hello World thingy. Because the developer tools (Visual Studio 2010 and the free Visual Studio 2010 Express) have pretty nice templates, that wasn’t much of a challenge. So I tried to build something real: an application that can display SharePoint 2010 content, for example items from an announcements list. I head to work my way around some limitations because both SharePoint 2010 and the developer tools are still in beta and CTP, but finally I got it working! Because of the many workarounds, the code is not yet ready for publication, but I’ve created a small screencast so you can see the result. To be continued! :-)

Windows Phone 7 POC: Getting SharePoint Data from Jan Tielens on Vimeo.

Two weeks ago I was in Iceland, talking about SharePoint 2010 at TM Software (some photos here :-) ). During the course, some students showed me a pretty cool public SharePoint 2007 site that they have been working on: OneResponse (http://oneresponse.info). OneResponse is the site the United Nations uses to collaborate and share information during catastrophes such as the recent earthquake in Haiti. Besides of the fact that the site is implemented really well, it must be pretty cool to know that your work will have such a big impact. Well done guys, it was a pleasure to be your guest!

Next week on Wednesday and Thursday I’ll be in Milano, Italy during the SharePoint & Office Conference 2010. They have a nice lineup of both Italian and international speakers to deliver 60 sessions during three days. I’ll be presenting four of them:

  • Client Side Technologies in SharePoint 2010
  • Building, Deploying and Managing Sandboxed Solutions
  • Advanced Web Part Development in SharePoint 2010
  • Silverlight and SharePoint 2010: Better Together

So, please come and say hi if you’re on the SharePoint Conference in Italy next week!

If you’re an avid reader of this blog, you are probably aware of the fact that using Javascript plus SharePoint is a very powerful combination. In SharePoint 2007 there were a couple of techniques you could use to make sure your Javascript files would be referenced by SharePoint pages:

  1. Add the Script reference to the Master Page
  2. Use a Delegate Control (e.g. the AdditionalPageHead)
  3. Dynamically through code, e.g. in a Web Part

Although all those techniques work, and will still work in SharePoint 2010, they all have some limitations. The first technique requires you to build a custom Master Page, which may be a little overkill just to get a Javascript file referenced. Additionally, your custom Master Page is not used on Application Pages (unless you use the Superbranding trick). The second is my favorite one in SharePoint 2007, but the requirement is that the Master Page you’re using has the corresponding Delegate Control, and you need to have either a Server Control or Web User Control that generates HTML to reference the script. The third technique is nice if you only want to use the script when the Web Part is on the page, otherwise you’ll have to put the Web Part on every page where you’d like to reference the script.

SharePoint 2010 is adding another very interesting technique to this list; using the ScriptSrc attribute of the CustomAction element in a Feature. Check the following Feature Elements file:

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomAction
      ScriptSrc="
JSDemo/jquery-1.4.2.js"
      Location="ScriptLink"
      Sequence="100"
      >
  </CustomAction>
</Elements>
 

The first important thing to notice is that the CustomAction element contains the ScrptSrc attribute that points in this example to the jQuery Javascript library. The jQuery library is added to the /_layouts folder in the SharePoint Root, in a folder called JSDemo (the /_layouts/ prefix is added automatically). By the way, adding files to the /_layouts folder is very easy in a SharePoint project in Visual Studio 2010, using a Mapped Folder.  The second important attribute is the Location; it must be set to ScriptLink so the Javascript file is referenced in the head element of the page. Optionally you can specify a Sequence attribute to determine the in which order the script references will be added (if you have multiple). When Feature is activated, it results in the following HTML:

document.write('<script type="text/javascript" src="http://weblogs.asp.net/_layouts/jsdemo/jquery-1.4.2.min.js?rev=EAku7lY97C3Kgrd9LPWhrg%3D%3D"></' + 'script>');

It’s important to mention that adding a reference to a script using this technique only works for scripts stored in the /_LAYOUTS folder in the SharePoint Root, so unfortunately it’s not possible to do something like this:

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomAction
      ScriptSrc="
http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.min.js"
      Location="ScriptLink"
      Sequence="100"
      >
  </CustomAction>
</Elements>

Besides the ScriptSrc attribute, you can also use the ScriptBlock attribute to render a script inline. The following example shows an annoying message box every time a pages load:

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomAction
      ScriptSrc="JSDemo/jquery-1.4.2.min.js"
      Location="ScriptLink"
      Sequence="100"
      >
  </CustomAction>
  <CustomAction
      Location="ScriptLink"
      ScriptBlock="$(document).ready(function() {
                      alert('jQuery is loaded!!'); });"
      Sequence="101"
    >
  </CustomAction>
</Elements>
 

Unfortunately the ScriptSrc attribute doesn’t work very well in combination with Sandboxed Solutions: you can’t add files to the SharePoint Root using Sandboxed Solutions, and the ScriptSrc attribute requires the referenced script to be in the SharePoint Root’s /_layouts folder. I’m still figuring out a nice way to add for example the jQuery library to a SharePoint site, only using a Sandboxed Solution. If I’m successful, you’ll can definitely read more about it in a future post! :-)

Last week I stumbled upon some pretty neat functionality of the out-of-the-box List View Web Part in SharePoint 2010: the AJAX Options. When you add a Web Part from the List and Libraries category (that basically shows you every List and Document Library you have on the SharePoint site) behind the scenes the Data View Web Part is being used to display the List or Document Library data.

When you edit such a Web Part once it has been added to a page, you’ll notice there is a new AJAX Options section in the Web Part properties. AJAX stands for Asynchronous Javascript and XML and is a web development technique to build more interactive, rich web sites. The AJAX Options are disabled by default, but by enabling you can get some pretty cool results:

  • Enable Asynchronous Update: enabling this option will make paging, sorting, filtering work without full page refreshes.
  • Show Manual Refresh Button: enabling this option will show an icon to allow the user the refresh the data manually, once again without refreshing the rest of the page.
  • Enable Asynchronous Automatic Refresh: when enabled, the Web Part will dynamically refresh the date it’s showing, without completely reloading the page. The interval can be specified in the textbox below.
  • Automatic Refreshing Interval: specifies the interval used in the previous option.
  • Enable Asynchronous Load: when enabled, the Web Part will initially be displayed without any data in it. But once the page is loaded, the Web Part will asynchronously fetch the data afterwards. When the data is being loaded, the Web Part will display an animation. This option will speed up the initial page load.
More Posts