Overview: Professional Windows Live Programming

Posted by admin in Live Spaces, ... | 11.16.2007 - 1:26 am

Overview: Professional Windows Live Programming

Wrox is about to release a book by Jon Arking titled “Professional Windows Live Programming”. As a Microsoft MVP, I was fortunate to get a pre-release copy.

The book does a good job highlighting the many services that makeup Windows Live, including:

While much of this information is already available on the web at dev.live.com (Microsoft’s developer site for everything Windows Live), the information presented in the book offers the reader a good “get your feet wet” understanding of each of the topics covered.

Even with this exhaustive list of Windows Live topics, there are some Windows Live technologies not covered in this book, including:

As a gadget developer, I would have liked to see an expanded section on Live Gadgets. However, the information that is present is concise and accurate. The book goes into some depth describing how to setup IIS on your local machine to develop gadgets locally.

If you are a developer looking to incorporate Windows Live services into your application, this book is for you. You will need a good working knowledge of DHTML, JavaScript, C# and Web Services.

Be aware that, as with any web technology, changes are happening almost every day; many times faster than print books can keep up. For example, Virtual Earth recently released version 6, but the book states the lastest version is version 5. Even so, this book makes a good read now and should make a handy quick reference tool for some time to come.

If you are interested in a sneak peak, Wrox has the following excerpts from the book in PDF format:

The book doesn’t officially go on sale until November 5th (at least here in the US), but you can pre-order the book from Amazon.com (who is offering a 5% discount on pre-order sales). You can also pre-order the book directly from the publisher.


Program to Windows Live Events? The Create Events API

Posted by admin in Live Spaces, Live Sp... | 11.16.2007 - 1:25 am

Program to Windows Live Events? The Create Events API

Rob Dolin, a Program Manager on the Spaces team, posts tonite with an example of a programmatically created Windows Live Event:

API Details
The link should have taken you to an event create page with all of the specified parameters pre-populated.  Yep, it’s a long link, but it’s intended to show all of the parameters (most of which are optional.)  Here’s the link in a more read-able format:

http://spaces.live.com/api.aspx
?wx_action=createEvent
&wx_targetSite=eventSpace
&wxp_name=Movie+Night:+Live+Free+or+Die+Hard
&wxp_alias=livefreeordiehard
&wxp_contactName=John+Smith
&wxp_contactPhone=206-555-1212
&wxp_location=Space+Needle
&wxp_address=4th+Ave.+and+Broad+St.+in+Seattle
&wxp_latlong=47.62061,-122.34942
&wxp_mapType=h
&wxp_mapZoom=18
&wxp_description=%3cimg%20src=’http://entimg.msn.com/i/150/mo/OneSheets/new3/LiveFreeorDieHard.jpg’%3e
&wxp_template=IIEventOscarParty.xml

As you can see, parameters are URL encoded.   The mapping parameters (mapType, mapZoom) are consistent with Virtual Earth.  Check out their interactive SDK for more info.

diehard

Dolin goes on to offer some ideas for potential uses, and a PS on RSS:

RSS
P.S. Publicly accessible events also include an RSS feed.  You can see this by adding /feed.rss to the event’s URL AND in additional to basic RSS elements like <title>, <link>, <description>, and <pubDate>; <geo> and <georss> elements are also included.

…read more on the Spaces Developer Platform blog.

With all of the talk about APIs (Application Programming Interface) and Microsoft lately, this is an interesting if not very well publicized development.  As of yet there’s no mention of this functionality on Dev.live.com or in the Windows Live SDK.  Certainly that must be changing soon.

Thanks to ViaWindowsLive for blogrolling this, although unlike Angus we think you should keep on reading LiveSide, too ;)


Photos and Windows Live Spaces: Embed photos or albums.

Posted by admin in Live Spaces, Live Sp... | 11.16.2007 - 1:25 am

Photos and Windows Live Spaces: Embed photos or albums.

The latest improvements coming to Windows Live Spaces introduced a few changes to the way photos are handled, but with all of the announcements about Events and the changes to SkyDrive, you may have missed what has just happened.  We thought we would provide a little primer on what is available for Windows Live Spaces and photos, as some of of the changes that have been appearing over the last few weeks are adding up to provide a nice set of services around photos. Brandon has been playing with the new photo features, and we thought we would too:

First, let’s go through some of the changes that had been added previously:

  • Integration with Windows Live Photo Gallery, including upload and download of photo albums from any Space
  • Hi-Res photo capabilities (up to 1600×1200) - called “optimize for printing”
  • Improved slide show controls, using a Flash player and Vista like photo controls

In addition, the new set of features released yesterday added some new capabilities:

  • Embed individual photos or slide shows in your blog or website
  • Post your photos on Facebook

So how does it all work?  Let’s run through an example, using a set of pictures I took this summer on a trip to beautiful downtown Quincy, WA.

To get started, once the pictures are transferred from camera to computer (something easily accomplished by Windows Live Photo Gallery, unless you’re Chris Jones), select the album you want to upload, select any or all pictures from that album, and click on the Publish tab in Windows Live Photo Gallery:

quincy4

Windows Live Photo Gallery will give you a choice of “optimize for printing”, checking this box will upload the photos in Hi Res, leaving it unchecked will compress the photos, saving space and time, but leaving you with lower quality photos.

quincy5

Once you publish your photos to Spaces, you can get to them from your Space or from your Spaces home page, by clicking on “Share Photos”.  There you are offered a series of choices:

quincy3

We want to embed the photos in this blog entry, so clicking Embed offers some code that we can copy and paste into our site (clicking on Blog It does much the same thing, but auto populates a Spaces blog entry with the code already):

quincy6

Copy the embed code and paste it into your blog post or website and you’re running a slideshow of your pictures:


Windows Live Spaces

Here’s the code for this slide show:

“<object classid=”clsid:d27cdb6e-ae6d-11cf-96b8-444553540000″ codebase=”http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0″ width=”320″ height=”240″ id=”PanAndZoom” align=”middle”><param name=”FlashVars” value=”assetsRSS=http://windowsliveside.spaces.live.com/photos/cns!629D3050E0813A28!533/feed.rss”><param name=”Movie” value=”http://sc1.sclive.net/12.2.1265.1006/Web/Parts/PhotoAlbum/script/slideshow.swf”><param name=”Src” value=”http://sc1.sclive.net/12.2.1265.1006/Web/Parts/PhotoAlbum/script/slideshow.swf”><param name=”WMode” value=”opaque”><param name=”Quality” value=”High”><param name=”SAlign” value=”LT”><param name=”Menu” value=”1″><param name=”Base” value=”"><param name=”AllowScriptAccess” value=”always”><param name=”BGColor” value=”000000″><param name=”SWRemote” value=”"><param name=”AllowNetworking” value=”all”><embed src=”http://sc1.sclive.net/12.2.1265.1006/Web/Parts/PhotoAlbum/script/slideshow.swf” quality=”high” FlashVars=”assetsRSS=http://windowsliveside.spaces.live.com/photos/cns!629D3050E0813A28!533/feed.rss” WMode=”opaque” width=”320″ height=”240″ name=”PanAndZoom” align=”middle” allowScriptAccess=”always” type=”application/x-shockwave-flash” pluginspage=”http://www.macromedia.com/go/getflashplayer”></embed></object><br/><a href=”http://windowsliveside.spaces.live.com/photos/cns!629D3050E0813A28!533″>Windows Live Spaces</a>”

Embedding a single photo is the same procedure, just choose “Embed this photo”.

What this means, and this goes for the Facebook embed as well, is that Spaces allows you to host pictures and then embed them on other sites, meaning that worries about storage, backup, site maintenance, etc is all taken care of by Spaces.  The changes Spaces made to the photo control a few months ago all make sense now, as it is not only possible but easy to embed slide shows or photos, hosted on Spaces, almost anywhere.  Oh, and by the way, this all works very nicely in Windows Live Writer, making the suite of services all working together quite powerful.


Windows Live Quick Apps – Contoso Bicycle Club Part 2

Posted by admin in Live Spaces, Live Sp... | 11.16.2007 - 1:24 am

Windows Live Quick Apps – Contoso Bicycle Club Part 2

LatestRides

Welcome back to the second part of our deep dive in the Windows Live Quick Apps Website featuring the Contoso Bicycle Club. In this part we’ll take a look at another custom user control found on the home page, the Latest Rides feed.

If you followed the first part of this deep dive then you will find a lot of things very similar with this control :-

<%@ Control Language=”C#” ClassName=”LatestRidesControl” %>

<div id=”latestRidesContent”>

<script runat=”server”>

int n = 1;

</script>

<!– setup the XML Datasource - this will query the RSS feed directly –>

<asp:XmlDataSource ID=”latestRidesDataSource” runat=”server” EnableCaching=”false”

DataFile=”<%$ AppSettings:LatestRidesFeed %>” XPath=”/rss/channel/item”></asp:XmlDataSource>

<table>

<asp:DataList ID=”latestRidesDataList” runat=”server” DataSourceID=”latestRidesDataSource”>

<ItemTemplate>

<tr class=”latestRideItem”>

<td valign=”top” class=”left”>

<a href=”BLOCKED SCRIPTshowDiv($(’contentPanel’), 100);updatePage(’<%# XPath(”title”) %>’,'<%= latestRidesDataSource.DataFile %>’, <%= n%> ,’<%# HtmlProcessor.ExtractMapCid(XPath(”description”).ToString()) %>’,'<%# HtmlProcessor.ExtractPhotoAlbumFeed(XPath(”description”).ToString()) %>’)”>

<img width=”50″ height=”50″ alt=”<%# XPath(”title”) %>” src=”<%# HtmlProcessor.ExtractImageUrl(XPath(”description”).ToString()) %>” />

</a>

</td>

<td class=”right”>

<div class=”title”>

<a href=”BLOCKED SCRIPTshowDiv($(’contentPanel’), 100);updatePage(’<%# XPath(”title”) %>’,'<%= latestRidesDataSource.DataFile %>’, <%= n++ %> ,’<%# HtmlProcessor.ExtractMapCid(XPath(”description”).ToString()) %>’,'<%# HtmlProcessor.ExtractPhotoAlbumFeed(XPath(”description”).ToString()) %>’)”>

<%# XPath(”title”) %>

</a>

</div>

<div class=”description”>

<%# HtmlProcessor.FirstLine(XPath(”description”).ToString()) %></div>

</td>

</tr>

</ItemTemplate>

</asp:DataList>

</table>

</div>

So let’s start at the top. The first thing you’ll see is a counter has been setup and initialized to 1. This serves the same purpose as the counter found in Events Control and simply gives each entry its own unique ID.

Next we set up the XML DataSource. This time however we’re point to a different entry in the web config file :-

<add key=”LatestRidesFeed” value=”http://contosobicycleclub.spaces.live.com/category/rides/feed.rss”/>

In the Event Control we pointed to the RSS feed gained from the Events category in the CBC Windows Live Spaces site, this time we’re pointing to the Rides feed. This feed will be used in more than one place in the sample web site but we’ll talk about it again when we get to that point in our deep dive. The XPath expression for our DataSource is the same as the one used the DataSource control in the Events Control. This is because the feed that is being distributed is based on a standard. You will find the same xml markup tags in every feed produced by Windows Live Spaces. This makes our jobs as developers easier.

XPath=”/rss/channel/item”

Here we are saying, from the root of the received feed, we are only interested in the xml that is encapsulated in the Item tag. The Item tag is found within the Channel tag which itself is found in the RSS tag under the root. The easy way to think about this is a folder hierarchy as you might find on your computer. An equivalent would be C:/Windows/System32. Here we’re looking for the contents of the System32 folder which is found under the Windows folder which is found under the root of the C: drive.

XPath expressions were designed this way so as to be easy to use and understand.

Next we start a table. This is being used purely for layout purposes as this control is slightly more complex than the Event Control and displays more data.

Within the table tag we start our repeating section using the DataList control. The DataList control gets its data from the XmlDataSource that we defined above.

We define a table row and a couple of table cells. As mentioned this is purely for presentation purposes. Within the first table cell we display an image.

<a href=” BLOCKED SCRIPTshowDiv($(’contentPanel’), 100);updatePage(’<%# XPath(”title”) %>’,'<%= latestRidesDataSource.DataFile %>’, <%= n%> ,’<%# HtmlProcessor.ExtractMapCid(XPath(”description”).ToString()) %>’,'<%# HtmlProcessor.ExtractPhotoAlbumFeed(XPath(”description”).ToString()) %>’)”>

<img width=”50″ height=”50″ alt=”<%# XPath(”title”) %>” src=”<%# HtmlProcessor.ExtractImageUrl(XPath(”description”).ToString()) %>” />

</a>

Don’t worry, it looks way more complicated than it actually is.

First, we define a link and rather than the link taking us to new page or section we’re running some custom Javascript inside it. The first statement simply calls a Javascript function that un-hides a DIV section that is defined in the default.aspx page.

function showDiv(div, zIndex) {

div.style.visibility = ‘visible’;

div.style.zIndex = zIndex;

// Work around for Bugzilla Bug 187435 for Firefox on Mac

if(div.id.toLowerCase() == “directionspanel” || div.id.toLowerCase() == “textpanel” || div.id.toLowerCase() == “mainpanel”)

{

div.style.overflow = “auto”;

}

}

As you can see from this javascript function, we simply take a reference to the div and show it with a z-index that is also passed in.

The only thing slightly unusual about this is the call to this function :-

BLOCKED SCRIPTshowDiv($(’contentPanel’), 100);

The javascript function showDiv is expecting a reference to the actual Div, not the name of the name of the Div as you may guess from contentPanel being enclosed in quotes. This is actually using a short cut notation that is found in Asp.Net Ajax. The actual expression is “$(‘contentPanel’)”. This is equivalent of saying :-

Document.getElementById(‘contentPanel’)

Which would be a reference to the Div itself and not just the name of the Div.

Next we have a call to another JavaScript function. This function call is slightly more complex as it is a generic function for use by virtually every control on the page and therefore there are some parameters to it that are essentially optional, depending on where the function is being called from. So lets go through this step by step.

The first parameter in the updatePage function call is title of the blog post :-

<%# XPath(”title”) %>

Remember that we have already extracted the xml down the item level. Each Item is a blog post itself. So here we’re simply saying, give me the contents of what’s found in the Title Xml element in the Item.

The next parameter is the whole RSS feed itself :-

‘<%= latestRidesDataSource.DataFile %>’

Next we pass in the value of the counter that was defined at the top of the user control. This essentially gives each repetition its own ID.

The next call is to static member of a class file found in the Classes folder of the website :-

<%# HtmlProcessor.ExtractMapCid(XPath(”description”).ToString()) %>

We make a call to ExtractMapCid method, this returns an id for a virtual earth map collection that is taken from within the description of the blog post. What is this?

If you open up http://maps.live.com, in the top right of the page you’ll see a dropdown for Collections. This was a feature added to virtual earth V5. You can create your own collections or browse other peoples collections that they have made public. Each collection has its own unique ID.

Here is the code that we are calling :-

public static string ExtractMapCid(string html)

{

// Create the RegEx (conditions are find anything (including URLs) which have cid={THECIDVALUE}

Regex regex = new Regex(”;cid=(.*?)&amp”);

// Execute a search/match against the regex

Match match = regex.Match(html);

if (match.Groups.Count > 1)

return match.Groups[1].Value;

else return “”;

}

What we’re doing here is parsing through the contents of the Description XML tag looking for anything that matches “;cid=” and the cid value. This cid value is the unique ID given to collections within the maps.live.com application and extracting that value out to be passed into our updatePage javascript function.

The final parameter for out updatePage function call makes a call to another static method found in the HtmlProcessor class file :-

<%# HtmlProcessor.ExtractPhotoAlbumFeed(XPath(”description”).ToString()) %>

This time (as the function name explains) we are looking for photoalbums.

public static string ExtractPhotoAlbumFeed(string html)

{

// Create a regex to find a spaces photoalbum url.

Regex regex = new Regex(”http://(.*?).spaces.live.com/.*?PhotoAlbum.*?(cns!.*?)&”);

Match match = regex.Match(html);

if (match.Groups.Count > 2)

return string.Format(”http://{0}.spaces.live.com/photos/{1}/feed.rss”, match.Groups[1].Value, match.Groups[2].Value);

else return “”;

}

This is a snippet from one of the blog posts :-

Finished ride near some really good places to eat at London Bridge.<br></span> </div>

<div>

<p><a href=”http://maps.live.com/default.aspx?v=2&amp;cid=2BACE20A0AB578FB!180&amp;encType=1″>Map</a>

<p><a href=”http://contosobicycleclub.spaces.live.com/?_c11_PhotoAlbum_spaHandler=TWljcm9zb2Z0LlNwYWNlcy5XZWIuUGFydHMuUGhvdG9BbGJ1bS5GdWxsTW9kZUNvbnRyb2xsZXI$&amp;_c11_PhotoAlbum_spaFolderID=cns!19C180FDFB1C7EFF!138&amp;_c11_PhotoAlbum_startingImageIndex=0&amp;_c11_PhotoAlbum_commentsExpand=0&amp;_c11_PhotoAlbum_addCommentExpand=0&amp;_c11_PhotoAlbum_addCommentFocus=0&amp;_c=PhotoAlbum”>Photos</a></div><div>

As you can see it’s basically HTML markup. Within here you will notice there is a link tag pointing to a photo album that matches our regular expression :-

http://contosobicycleclub.spaces.live.com/?_c11_PhotoAlbum_spaHandler=TWljcm9zb2Z0LlNwYWNlcy5XZWIuUGFydHMuUGhvdG9BbGJ1bS5GdWxsTW9kZUNvbnRyb2xsZXI$&amp;_c11_PhotoAlbum_spaFolderID=cns!19C180FDFB1C7EFF!138&

The regular expression splits this down into 3 separate groups. The first group is the whole string above, the second is initial value found after http:// as defined by :-

http://(.*?)

And the third group is the cns number as defined in the regular expression by :-

(cns!.*?)

What we are really looking for is the second and third values. These are plugged into the return string :-

string.Format(”http://{0}.spaces.live.com/photos/{1}/feed.rss”,match.Groups[1].Value, match.Groups[2].Value);

And so what you actually end up with is this url :-

http://contosobicycleclub.spaces.live.com/photos/cns!19C180FDFB1C7EFF!138/feed.rss

In the middle of the link (anchor tag) an image is placed :-

<img width=”50″ height=”50″ alt=”<%# XPath(”title”) %>” src=”<%# HtmlProcessor.ExtractImageUrl(XPath(”description”).ToString()) %>” />

Following the same logic we have thus far, the alt parameter is defined as the title of blog and src parameter point to what is returned from the call to ExtractImageUrl, another static function call found in the HtmlProcessor class :-

public static string ExtractImageUrl(string html)

{

// Create a RegEx to find the Image

Regex regex = new Regex(”<img.*?src.*?=.*?\”(.*?)\”", RegexOptions.IgnoreCase);

// Execute the search/match.

Match match = regex.Match(html);

if (match.Groups.Count > 1)

return match.Groups[1].Value;

else return “”;

}

Once again we are using regular expression pattern matching to look for a specific value.

If you take a look at the source for the RSS feed, look towards the end of the first <item> tag, just before all the comments and you’ll see the following (even if you just look at the rss feed itself in IE7, you’ll see a picture attached to the end of each post) :-

img src=”http://storage.live.com&amp;#47;items&amp;#47;19C180FDFB1C7EFF&amp;#33;131&amp;#58;thumbnail

This is what we’re extracting out, the value for the source of this image tag.

The contents of the second table cell are exactly the same as the content for the Event Control (see previous article for details). The only difference between the two is that the second and third parameters for the updatePage function call actually have values this time (as explained above for the first table cell).

And there you have it, the Latest Rides user control from the Contoso web site. It’s almost identical to the Events user control, but this time we looked at a different feed and extracted out slightly more information from the description tag to enable us to display images (and also information that will be used by other controls on the page but isn’t really apparent in the display of the Latest Rides control).

So let’s extract what we’ve learned here and build upon our very basic page from the previous article.

Open up the website you created from the previous article and open the default.aspx page.

What we’ll be doing is simply adding an image next to the title for each blog post and display the first image we find that is contained within the blog in this spot.

So here is the default page from yesterday :-

<%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”Default.aspx.cs” Inherits=”_Default” %>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>

<html xmlns=”http://www.w3.org/1999/xhtml” >

<head runat=”server”>

<title>Untitled Page</title>

</head>

<body>

<form id=”form1″ runat=”server”>

<div>

<asp:TextBox ID=”Feed” runat=”server” Columns=”60″ />

<br />

<asp:Button ID=”btnSubmit” runat=”server” OnClick=”btnSubmit_Click” Text=”Get Feed” />

<br />

<br />

<asp:XmlDataSource ID=”source” runat=”server” XPath=”/rss/channel/item” DataFile=”http://msnwindowslive.spaces.live.com/feed.rss” />

<asp:Repeater DataSourceID=”source” ID=”DisplayFeed” runat=”server”>

<ItemTemplate>

<div>

<a href=’<%# XPath(”link”) %>’>

<%# XPath(”title”) %>

</a>

<hr />

<%# GetFirstXCharacters(XPath(”description”).ToString(), 900)%>

<br />

<br />

</div>

</ItemTemplate>

</asp:Repeater>

</div>

</form>

</body>

</html>

Now all that we need to do is insert the following image tag just before the <%# XPath(”title”) %> that is found in the link :-

<img width=”50″ height=”50″ alt=”<%# XPath(”title”) %>” src=”<%# ExtractPics(XPath(”description”).ToString()) %>” />

Now go into your code behind and add the ExtractPics static method as so :-

public static string ExtractPics(string description)

{

Regex regex = new Regex(”<img.*?src.*?=.*?\”(.*?)\”", RegexOptions.IgnoreCase);

Match match = regex.Match(description);

if (match.Groups.Count > 1)

return match.Groups[1].Value;

else return “”;

}

This is basically the same pattern matching expression that we discussed above in the article. And that’s all there is to it.

In the next part of this deep dive we’ll be taking a look at the main body of the page which is really where the fun starts.


Windows Live Quick Apps – Contoso Bicycle Club

Posted by admin in Live Spaces, Live Sp... | 11.16.2007 - 1:23 am

The Contoso Bicycle Club is a demonstration website put together to show off a number of Windows Live technologies and how easy it is to integrate these technologies into your own websites. The source code for both this web site and a second web site entitled Contoso University are available for download from CodePlex.

One note before we proceed any further. Both of these websites are written to run with Visual Studio Orcas (Beta 2 and above). Both applications also use Asp.Net Ajax and the Contoso Bicycle Club also requires the Asp.Net Ajax Toolkit. Both Asp.Net Ajax, the Toolkit and also Asp.Net Ajax Futures are freely downloadable from here.

So lets start at the beginning with a quick run through of the home page. Once you have everything setup and run CBC website, you will be greeted with a rather nice looking home page :

BikeClubMain

The default.aspx page (above) is coded in a nice way, splitting the page into a number of manageable user controls which are registered at the top of the page (we’ll get into these later). A quick look through the code and you’ll notice that the default.aspx page also takes advantage of .Net 2.0 Themes. The default theme (named default) is coded into the web.config file :-

<pages theme=”Default” enableViewState=”false”>

Next is the inclusion of the Asp.Net Ajax ScriptManager tag and within there a number of scripts are registered with the page. Most of these scripts are included in the application however there are two noticeable scripts that have external references (therefore in order to run this website locally you still need an internet connection). One of the scripts references the Virtual Earth MapControl and the other is a Silverlight helper file.

Below the ScriptManager tag the site defines a couple of areas that will be used for Ride information (using a user control) and Events (again using a user control).

Next the default.aspx defines a number of menu tabs (as you can see along the top of the page). These are coded in a “W3C friendly layout” as opposed to using tables to position everything.

The main area of the page is mostly taken up with an area reserved for the map control (initially hidden).

An embedded iFrame tag sets up a slideshow and finally a few more areas are defined for directions, a text only panel, the footer you see along the bottom of the page giving you links to the source and a live site website where this demonstration site is actually being hosted, and an area reserved for the Main page.

The code behind for the default page simply returns the images for use in the slideshow iFrame.

So now that we have a quick outline of the home page, lets dig in a little further, see what the user controls do and see exactly how this page is put together. We’ll start out easy.

Events Control

EventsControl

This control which displays on the bottom left of the page takes an RSS feed gathered from a Windows Live Spaces site, formats it and displays it. So how is this done?

Every Windows Live Spaces site exposes various RSS feeds by default. You have a main feed that details all the posts that you have made. You also get individual feeds for each category that you file a post under. Some categories are predefined for you but you have complete freedom in adding your own categories. The easiest way of doing this is to simply fire up Live Writer. At the bottom of Live Writer there is a categories drop down, here you add a new category when you post a blog and this will be created in Spaces for you. You also need to go to your spaces site, login and select “Space settings” from the options menu and make sure that you have syndication turned on.

To get the URL that you require is very easy. For your main “everything” RSS feed, it’s simply the URL of your spaces site followed by “/feed.rss”. If you want a feed for a specific category then again it’s simple, take the URL to your spaces site and add “/category/” followed by the category that you wish followed by “/feed.rss”.

For example, one of my spaces sites resides at http://msnwindowslive.spaces.live.com.

To get the feed for the whole site would simply be http://msnwindowslive.spaces.live.com/feed.rss. To get the feed for a category I’ve setup called Books it would simply be http://msnwindowslive.spaces.live.com/category/books/feed.rss.

Now that you know how the spaces feeds are constructed, take a look in the Web.config file of the CBC web site and under the AppSettings section you will notice that this application actually uses three separate RSS feeds from Windows Live Spaces :-

<appSettings>

<!– Content Feeds - RIDES –>

<add key=”LatestRidesFeed” value=”http://contosobicycleclub.spaces.live.com/category/rides/feed.rss”/>

<!– Content Feeds - FORUM –>

<add key=”ForumFeed” value=”http://contosobicycleclub.spaces.live.com/category/forum/feed.rss”/>

<!– Content Feeds - EVENTS –>

<add key=”EventsFeed” value=”http://contosobicycleclub.spaces.live.com/category/events/feed.rss”/>

….

</appSettings>

The one that we’re currently interested in is the EventsFeed. As you can see this is pointing to http://contosobicycleclub.spaces.live.com/category/events/feed.rss. You can right click and view source to take a look at the xml if you wish.

So back to the Events Control.

At the top of the control a JavaScript variable is initialized to 1. This is a counter that will be used in a JavaScript function to effectively give each blog its own item number (ID).

Next a XmlDataSource is defined. Nothing fancy here although a couple of things may appear to be unusual.

<asp:XmlDataSource ID=”eventsDataSource”

runat=”server”

EnableCaching=”false”

DataFile=”<%$ AppSettings:EventsFeed %>”

XPath=”/rss/channel/item”>

</asp:XmlDataSource>

The DataFile path uses a shortcut that was introduced in Asp.Net 2.0 to EventsFeed item found in the AppSettings section of the web.config file.

This is essentially equivalent to the following line of code :-

ConfigurationManager.AppSettings[”EventsFeed”]

The other is the Xpath setting. This is just a normal XPath path. You can think of it like a folder heirarchy. If you take a look at the actual RSS feed, you’ll see that “rss” is the top level element, under that there is a single channel tag that encapsulates the whole feel then there are a number of tags detailing such things as the title, a description, a link back to the actual article and so on. The one we’re interested is the item tag and all the tags under that item tag. There will be one item tag per blog post. Under each item you will find tags such as a link back to that specific blog post, the title of the blog, the date is was written, a permalink, any comments etc.

So in effect what we have done with the above XmlDataSource is to create a data feed for all blog posts found in the Contoso Windows Live Spaces site that have been filed under the category of Events.

Next we have a DataList control, which is just another repeater control. The DataList control takes in the XmlDataSource then defines how to display the data. It goes through each item (blog post) and applies a display template to it. In this example there are basically two different sections.

<div class=”title”>

<a href=”BLOCKED SCRIPTshowDiv($(’contentPanel’), 400);updatePage(’<%# XPath(”title”) %>’,'<%= eventsDataSource.DataFile %>’, <%= n++%> ,’<%# HtmlProcessor.ExtractMapCid(XPath(”description”).ToString()) %>’,'<%# HtmlProcessor.ExtractPhotoAlbumFeed(XPath(”description”).ToString()) %>’)”>

<span class=”subTitle”><%# XPath(”title”) %></span>

</a>

</div>

The first output above may look complicated but it’s really not. First we’re defining a link. Within the link we’re first telling it to unhide the contentPanel that is defined in the default.aspx. The second parameter is simply the z-index. Here is the Javascript function that it calls :-

// Shows a DIV tag

function showDiv(div, zIndex) {

div.style.visibility = ‘visible’;

div.style.zIndex = zIndex;

// Work around for Bugzilla Bug 187435 for Firefox on Mac

if(div.id.toLowerCase() == “directionspanel” || div.id.toLowerCase() == “textpanel” || div.id.toLowerCase() == “mainpanel”)

{

div.style.overflow = “auto”;

}

}

Barring the Firefox workaround, as you can see, very straightforward.

Next we call the updatePage javascript function passing through some parameters. The first parameter is the Blog Title taken from the XmlDataSource, the next is the actual blog post itself, the third is the counter that was defined at the top of the page. Think of this as an ID number. The last two parameters for the javascript function call both use a class you will find in the Classes folder of the project, HtmlProcessor.

The first makes a call to ExtractMapCid, this returns an id for a virtual earth map collection that is taken from within the description of the blog post.

The second makes a call to ExtractPhotoAlbumFeed which returns a url to a Windows Live Spaces photo album RSS feed.

The Events Control however does not use maps or photographs therefore these last two parameters always return empty strings after the call the HtmlProcessor.

Embedded in the link is the actual text that will be displayed and for this we’re simply putting the title of the blog post within a <span> tag.

After all is said and done, this is the output for the first blog post from the Bicylcle club :-

<div class=”title”>

<a href=”BLOCKED SCRIPTshowDiv($(’contentPanel’), 400);updatePage(’North End’,'http://contosobicycleclub.spaces.live.com/category/events/feed.rss’, 1 ,”,”)”>

<span class=”subTitle”>North End</span>

</a>

</div>

We show the contentPanel for events, display the title as a hyperlink with the link calling a javascript function to update the page passing through the title of the blog post, the whole blog post feed and an ID number.

The second part of the DataList calls the HtmlProcessor class once again :-

<div class=”description”>

<%# HtmlProcessor.FirstLine(XPath(”description”).ToString()) %>

</div>

This time we’re calling the function FirstLine and passing in the contents of the description Xml tag taken from the XmlDataSource for that blog post :-

public static string FirstLine(string html)

{

Regex regex = new Regex(”(.*?)\\.”);

Match match = regex.Match(html);

if (match.Groups.Count > 1)

return match.Groups[1].Value;

else return “”;

}

This is a fairly simple function that parses through the passed in html looking for the first full stop at the end of a sentence and extracts that sentence. The returned sentence is what will be displayed on screen.

That’s all there is to this user control, simple. So how do you incorporate this into your own websites without all the fancy javascript etc. from the Bicycle application?

SimpleApp

Fire up Visual Studio and create a new Web Site. For this example we just need to create a standard web site (don’t need Ajax). For this demo we’re simply going to put a textbox on the page to enter the location of a spaces feed, a button control so that we can take the value entered and bind it to our data source control, and a repeater to display the contents.

We won’t bother with CSS to make things look nice as this example is just here to show how easy it is to display a Windows Live Spaces RSS feed in your own site, you can add a stylesheet to this code if you so wish.

So after the project has been created, we need to create our controls on the default.aspx page as described above. Here is the simple code for our default.aspx page :-

<%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”Default.aspx.cs” Inherits=”_Default” %>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>

<html xmlns=”http://www.w3.org/1999/xhtml” >

<head runat=”server”>

<title>Untitled Page</title>

</head>

<body>

<form id=”form1″ runat=”server”>

<div>

<asp:TextBox ID=”Feed” runat=”server” Columns=”60″ />

<br />

<asp:Button ID=”btnSubmit” runat=”server” OnClick=”btnSubmit_Click” Text=”Get Feed” />

<br />

<br />

<asp:XmlDataSource ID=”source” runat=”server” XPath=”/rss/channel/item” DataFile=”http://msnwindowslive.spaces.live.com/feed.rss” />

<asp:Repeater DataSourceID=”source” ID=”DisplayFeed” runat=”server”>

<ItemTemplate>

<div>

<a href=’<%# XPath(”link”) %>’>

<%# XPath(”title”) %>

</a>

<hr />

<%# XPath(”description”) %>

<br />

<br />

</div>

</ItemTemplate>

</asp:Repeater>

</div>

</form>

</body>

</html>

All very simple. The code behind is even simpler :-

using System;

using System.Data;

using System.Configuration;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

}

public static string GetFirstXCharacters(string description, int x)

{

return description.Substring(0, x);

}

protected void btnSubmit_Click(object sender, EventArgs e)

{

source.DataFile = Feed.Text;

}

}

For the above example, the only method that we require is the btnSubmit_Click event handler. In this we simply set the datafile (RSS feed) of our DataSource control to the value that has been entered into the textbox, and that’s it. Of course in a real web application you would parse the value entered to make sure that it was correct and add error handling.

The other method in this web config file simply returns the first x characters of each blog description. In order to hook the code up to use this method you simply replace the line in the default.aspx page that reads :-

<%# XPath(”description”) %>

With this :-

<%# GetFirstXCharacters(XPath(”description”).ToString(), 500) %>

Of course you can replace this with any method call that you wish, for example to parse the description field to extract certain values.

In the next part of this tutorial we will move onto the Latest Rides control.


SkyDrive With Spaces and Writer [Plugin Updated]

Posted by admin in Live Spaces, Live Sp... | 11.16.2007 - 1:17 am

SkyDrive With Spaces and Writer [Plugin Updated]

With SkyDrive not even 6 hours old, we already have our first addins for it. The Spaces and SkyDrive team have just unveiled a new module for your Windows Live Space, one that shows the public folders you have on your SkyDrive account. To access it, sign into your Space, click on the Customize button and add module and go to the Windows Live section.

image

The module will look like this when viewed in non-edit mode:
image

And for Writer we have a plugin that will allow you to put the embed code for a public SkyDrive folder into your blog entry, written, and shamelessly promoted, by me.

image

I’m just waiting for the plugin to be approved by Windows Live Gallery, but in the meantime, you can download, funnily enough, from my SkyDrive Space smile_wink Plugin is now available on Windows Live Gallery. Full source code available too.

Source code: http://www.codeplex.com/SkyDriveEmbedPlugin
Download Plugin: http://gallery.live.com/liveItemDetail.aspx?li=27545581-4b54-4f6d-9007-ed3b168dab43

Update: Apologies, this is the first plugin I have created using Visual Studio 2008, and the setup defaults to having .NET 3.5 as a prerequisite, I have changed this and it now only requires .NET 2.0, not 3.5. The link is the same, so if you are having problems, just download it again. Sorry.

Update 2: As any of you who know me will know, I am never happy with my plugins, so I have made a slight amendment to it. At the moment, the way the embedding works from SkyDrive is to use an iFrame tag, now this gets stripped by a few blog services, so I have given the option of turning off iFrame mode and using the plugin to do all the hard work, the end result will be the same though. The download link above is still the same, but it now points to the updated version (if you want to check, the dll should be version 1.0.1.0)


Windows Live SkyDrive beta update brings minor but convenient changes

Posted by admin in Live Spaces, Live Sp... | 11.16.2007 - 1:17 am

Windows Live SkyDrive beta update brings minor but convenient changes

Today the Windows Live SkyDrive team released an updated version of the SkyDrive online storage service. While the service stays in beta for now this release incorporates several minor but very convenient changes that are detailed in their team blog.

Let’s talk marketing and numbers first. The amount of storage space you get with your free account has been doubled - so everyone can save 1GB online. In an interview with the team we were told that storage space should never be a problem for the user. They looked at home and business users and the amount of files they would need to store online and will continue to monitor this need for future storage increases.

skydrive2

UI wise the first thing the user will notice is that Windows Live SkyDrive is moving towards the Windows Live Spaces umbrella in the same way that Windows Live Events is going to placed when launched. Right below the Windows Live Wave 2 header you get direct access to different parts of Windows Live Spaces. Your Spaces homepage (What’s new), spaces, friends, photos, and events can be reached from here.

skydrive5

Pretty cool is the addition of Feeds (RSS) to Public folders. This way you can easily be notified of updates to content that friends place in their Public folders. Simply go to the Public folder and click on the Feed icon in the upper right corner (or the Feed icon in IE for example). The feed contains a preview image of the added files - either a small version of the photo or the file type icon and links to the associated download page for that file on Windows Live SkyDrive.

skydrive3

In order to share a folder not with everyone but a select group of users these already had to be in your contact list and you had to go to Windows Live Messenger or Windows Live Hotmail and add a person there before you could share content with them. Now you can simply add the contact right when and where you need it - the folder permissions page.

skydrive4

Last but not least Windows Live SkyDrive isalso displaying who has uploaded a certain file now which can be helpful is you have given full access to a folder and want to keep track of who is uploading what.

skydrive1

All of the changes are live now so you can try them out on Windows Live SkyDrive.


Windows Live Spaces takes aim at Facebook’s News Feed

Posted by admin in Live Spaces, Live Sp... | 11.16.2007 - 1:16 am

Windows Live Spaces takes aim at Facebook’s News Feed

Microsoft rolled out a killer feature that we haven’t talked about yet in their last Windows Live Spaces update.  They are calling it “Windows Live What’s New” and it acts as a direct competitor to Facebook’s News Feed.  I am really glad that they decided to include this feature in the latest release since the News Feed continues to be my absolute favorite feature of Facebook.

What’s New gives you information on what you friends are doing in six different areas: blogs, photos, lists, files, friends, and profiles.  Unfortunately, at this time, events are not included in the feed, but I would assume that they will be included in a later release once Events is more established.

Something else worth noting is that my current top post on Windows Live Spaces occurred about five minutes ago, while the current top item on my Facebook News Feed occurred around two hours ago.  So, it seems that the way that they have Windows Live What’s New fetching information is quicker than the way that Facebook is doing it (although this is not confirmed).

If you want to know more about Windows Live What’s New, make sure to check out Rob Dolin’s (Program Manager for the Spaces Home experience) blog post about it.  You can also check out Dare Obasanjo’s commentary on WL What’s New (he also noticed the speediness of the updates).  It’s good to see Microsoft and Facebook in some healthy competition, despite all of the acquisition rumors.


Windows Live Spaces at a crossroads: will the US catch up to the world?

Posted by admin in Live Spaces, Live Sp... | 11.16.2007 - 1:16 am

Windows Live Spaces at a crossroads: will the US catch up to the world?

One thing the LiveSide Stickers Around the World project really brought home, for someone who lives and breaths a US-centric life, was how much goes on in the world that is not neccesarily happening in the US.  I watched Robert Scoble whiteboard the Techmeme phenomenon recently, and noted his comments on how Techmeme in particular, and A-Listers in general, were English speaking and US centric.  Over here, its been all Facebook all the time lately, but when I ran across some ComScore numbers on Social Networking sites around the world, it got me to thinking, and to digging a little deeper.

Now before we get started it may be a good idea to talk about terms a bit.  Of course some would argue that Blogger or WordPress or even Windows Live Spaces aren’t “Social Networking sites”, and if you mean that they’re not like Facebook, then you’re probably right.  However these are sites that people use to connect with their friends, to share their thoughts and ideas, and to learn more about each other.  That all of them don’t have a development platform (yet), or that Scoble doesn’t maintain 5,000 friends in Spaces or Blogger, really is part of the issue here.  For now, let’s let the users define what a Social Networking site is by what they actually use.

ComScore was good enough to provide me with a very interesting set of numbers:  Social Networking sites, by unique visitors per month (all ages 15 and over), broken down by region.  I fired up Excel 2007 and knocked out some charts of the data, which Sarah from Comscore was kind enough to provide in a spreadsheet.  Let’s start with the North America numbers:

(click on any of the graphs for a larger image)

Social Networking Sites - North America: Unique visitors per month (000)

NorthAmerica

As expected, MySpace is in a runaway lead, Facebook is coming on strong, Blogger is hanging in there, and Spaces pretty much brings up the rear.  If you read the blogs and follow Techmeme, TechCrunch, and Scoble, these numbers aren’t anything surprising.

But take a look at the Worldwide numbers, and a somewhat different story emerges.

Social Networking Sites - Worldwide: Unique visitors per month (000)

Worldwide

While Facebook is growing steadily worldwide, here the numbers tell a far different story.  Windows Live Spaces is battling it out with Blogger and MySpace for the top spot.  Just for reference, we can see that the Worldwide usage of Social Networking sites is growing steadily:

Social Networking Sites: Total Worldwide unique visitors per month to the top ten sites (000)

TTLWorldWide

(note also here that for clarity I took the top 6 sites for each region, but the totals above represent worldwide numbers for the top 10 sites)

So 800,000,000 unique visitors in the month of September 2007 to the top 10 Social Networking sites around the world.  Not an inconsequential number.

In Europe, Spaces and Blogger again are leading the pack:

Social Networking Sites - Europe: Unique visitors per month (000)

Europe

And in the Asia Pacific region, similar numbers for Spaces, but a whole new set of competitors, MySpace and Facebook not among them:

Social Networking Sites - Asia Pacific: Unique visitors per month (000)

AsiaPacific

Lots of talk about Orkut in Latin America (well, Brazil):

Social Networking Sites - Latin America: Unique visitors per month (000)

LatinAmerica

but Orkut is still not anywhere close to Spaces and Blogger. And to round out the numbers, in the Middle East and Africa:

MiddleEastAfrica

where again it is Spaces and Blogger at the top, with Facebook definitely making a move.

Fun with numbers

So what does it all mean?  For one thing, the future for Windows Live Spaces does not appear to be as bleak as US pundits make it out to be.  If anything, the competition with Blogger may be much more of a challenge worldwide for Spaces than Facebook or MySpace.  Certainly the market seems lucrative, with lots and lots of people blogging and posting pictures and sharing.  Spaces just upgraded its photo storage and sharing capabilities, already has the basics of a friends network in place, and all indications are that it will soon begin a migration of MSN Groups into a new Windows Live Groups to complement the recently announced Windows Live Events.  Spaces also offers tight integration with Windows Live Messenger and Windows Live Hotmail, and Messenger integration is something both Blogger and Facebook lack, or at least not integration with some 300 million Windows Live Messenger users.  Certainly Spaces has had its share of growing pains.  The old way it handled photos was unacceptable, really, but that has been addressed if not totally fixed.  Although Spaces has been out of beta since April 2005, it is only just coming into its own in feeling like a complete product, but there is a lot of work left to do.

Mary Jo Foley wrote recently on Microsoft’s seeming reluctance to promote Spaces within the US, and indeed if you read the press in the US or follow the blogs, Windows Live Spaces is not much more than an also ran.  From looking at these numbers, though, and the discrepancies between the US numbers and those worldwide, my US centric colleagues and mentors may be a little premature in crowning Facebook king of the social network sites.

A note on Comscore

comscore

The numbers used in preparation of this post were provided free of charge from ComScore, with no strings attached, and for that we thank them.


Windows Live Spaces Photos API

Posted by admin in Live Spaces, Live Sp... | 11.16.2007 - 1:15 am

Windows Live Spaces Photos API

livespaces_logo Last week I mentioned about the Windows Live Tools for Visual Studio that came up for download on Connect, well this week, I will be mentioning the Windows Live Spaces Photos API (alpha), which has also just come up for download under the same Connection on Connect.

Angus Logan briefly mentioned it on his blog last week in a video interview that he did, which certainly got my attention, and it appears it is now readily available.

The download itself is simply a CHM file with all the documentation and code examples in it, so expect my normal “How To” guide on how to use it. So get cracking, download the documentation and let us know if you plan to use it.

SL




eXTReMe Tracker