The Logging Database is one of the many new concepts that will make the life of many SharePoint administrators quite a bit more enjoyable. In SharePoint 2007 the Unified Logging System (ULS) logged all of its data to text files, typically found on your SharePoint server in 12\LOGS. We still have that in SharePoint 2010, but besides those text files, ULS can also write the data to a database! The advantages are obvious: easy to query, one central location for all servers in the farm, easy to build reports etc. You can find this ULS data in the SharePoint 2010 logging database (typically called WSS_Logging), in the view ULSTraceLog.

Quite recently on one of my demo machines (standalone installation on Windows 7) I noticed the ULSTraceLog view was not available in the logging database. It turned out that there is a Timer Job that’s responsible for writing the data to the database, when the Timer Job hasn’t executed, the view is not there (the first time it executes, the view is created). Even more, the timer job was disabled, so the view would never be created, nor any data would be written to the database. If you encounter this situation as well, it’s quite easy to solve:

  1. Open the SharePoint Central Administration site
  2. Navigate to the Monitoring section
  3. Select Review Job Definitions
  4. Click on the job with the name Diagnostic Data Provider: Trace Log
  5. Click on the Enable button to enable it
  6. Optionally click on Run Now afterwards, to start it immediately

There you go, the ULSTraceLog will be created and the ULS messages will appear in the database!

A couple of weeks ago, the Belgian Techdays were held in Antwerp. Together with Scott Hillier I presented the SharePoint pre-conference sessions (watch them online over here, search for pre-conference or SharePoint). Even though Belgium is not a very big country, the Microsoft team managed to get some high profile speakers like Anders Hejlsberg and Scott Hanselman. But if you have like 60 minutes to spare there is one session that I'd really recommend to check out, not related to SharePoint, but very interesting and entertaining nonetheless: 5 Things SQL Server does different from what many developers expect by my U2U colleague Nico Jacobs. Nico did a fantastic job, so sit back and enjoy! :-)

Yesterday I tried to deploy a Business Data Connectivity Model project created in Visual Studio 2010 to my SharePoint 2010 test server (all RTM versions), but during the deployment of the solution, SharePoint threw my following error:

Add Solution:
  Adding solution 'BCSDemo2.wsp'...
  Deploying solution 'BCSDemo2.wsp'...
Error occurred in deployment step 'Add Solution': The default web application could not be determined. Set the SiteUrl property in feature BCSDemo2_Feature1 to the URL of the desired site and retry activation.
Parameter name: properties

A little bit of searching on the internet taught me that I was not the only one having this issue, actually Paul Andrew describes how to solve it in this post. Although Paul describes what to do, his explanation is not, let’s say, very elaborate. :-) So let’s describe the steps a little bit more in detail:

  1. Create a new Business Data Connectivity Model project in Visual Studio 2010 and (optionally) implement all your code, change the model etc. When you try to deploy you get the error mentioned above.
  2. To fix it, in the Solution Explorer, navigate to and open the Feature1.Template.xml file (the name could be different if you decided to give your feature a different name of course).
  3. Add the following XML in the Feature element that’s already there (replace the Value with the URL of your site of course):
      <Properties>
        <Property Key='SiteUrl' Value='http://spf.u2ucourse.com'/>
      </Properties>

    The resulting XML should look like:

    <?xml version="1.0" encoding="utf-8" ?>
    <Feature xmlns="
    http://schemas.microsoft.com/sharepoint/">
      <Properties>
        <Property Key='SiteUrl' Value='http://spf.u2ucourse.com'/>
      </Properties>
    </Feature>
  4. Deploy the solution, now without any issues. :-)

What happens now, is that when Visual Studio creates the SharePoint Solution (the WSP file), it will use the Feature template XML to generate the Feature manifest, which will now include the missing property.

Consuming SharePoint 2010 data in Windows Phone 7 applications using the CTP version of the developer tools is quite a challenge. The issue is that the SharePoint 2010 data is not anonymously available; users need to authenticate to be able to access the data. When I first tried to access SharePoint 2010 data from my first Hello-World-type Windows Phone 7 application I thought “Hey, this should be easy!” because Windows Phone 7 development based on Silverlight and SharePoint 2010 has a Client Object Model for Silverlight. Unfortunately you can’t use the Client Object Model of SharePoint 2010 on the Windows Phone platform; there’s a reference to an assembly that’s not available (System.Windows.Browser).

My second thought was “OK, no problem!” because SharePoint 2010 also exposes a REST/OData API to access SharePoint data. Using the REST API in SharePoint 2010 is as easy as making a web request for a URL (in which you specify the data you’d like to retrieve), e.g. http://yoursiteurl/_vti_bin/listdata.svc/Announcements. This is very easy to accomplish in a Silverlight application that’s running in the context of a page in a SharePoint site, because the credentials of the currently logged on user are automatically picked up and passed to the WCF service. But a Windows Phone application is of course running outside of the SharePoint site’s page, so the application should build credentials that have to be passed to SharePoint’s WCF service. This turns out to be a small challenge in Silverlight 3, the WebClient doesn’t support authentication; there is a Credentials property but when you set it and make the request you get a NotImplementedException exception.

Probably this issued will be solved in the very near future, since Silverlight 4 does support authentication, and there’s already a WCF Data Services download that uses this new platform feature of Silverlight 4. So when Windows Phone platform switches to Silverlight 4, you can just use the WebClient to get the data. Even more, if the OData Client Library for Windows Phone 7 gets updated after that, things should get even easier! By the way: the things I’m writing in this paragraph are just assumptions that I make which make a lot of sense IMHO, I don’t have any info all of this will happen, but I really hope so.

So are SharePoint developers out of the Windows Phone development game until they get this fixed? Well luckily not, when the HttpWebRequest class is being used instead, you can pass credentials! Using the HttpWebRequest class is slightly more complex than using the WebClient class, but the end result is that you have access to your precious SharePoint 2010 data. The following code snippet is getting all the announcements of an Annoucements list in a SharePoint site:

HttpWebRequest webReq =
    (HttpWebRequest)HttpWebRequest.Create("
http://yoursite/_vti_bin/listdata.svc/Announcements");
webReq.Credentials = new NetworkCredential("username", "password");

webReq.BeginGetResponse(
    (result) => {
        HttpWebRequest asyncReq = (HttpWebRequest)result.AsyncState;

        XDocument xdoc = XDocument.Load(
            ((HttpWebResponse)asyncReq.EndGetResponse(result)).GetResponseStream());

        XNamespace ns = "http://www.w3.org/2005/Atom";
        var items = from item in xdoc.Root.Elements(ns + "entry")
                    select new { Title = item.Element(ns + "title").Value };

        this.Dispatcher.BeginInvoke(() =>
        {
            foreach (var item in items)
                MessageBox.Show(item.Title);
        });
    }, webReq);

When you try this in a Windows Phone 7 application, make sure you add a reference to the System.Xml.Linq assembly, because the code uses Linq to XML to parse the resulting Atom feed, so the Title of every announcement is being displayed in a MessageBox. Check out my previous post if you’d like to see a more polished sample Windows Phone 7 application that displays SharePoint 2010 data.
When you plan to use this technique, it’s of course a good idea to encapsulate the code doing the request, so it becomes really easy to get the data that you need. In the following code snippet you can find the GetAtomFeed method that gets the contents of any Atom feed, even if you need to authenticate to get access to the feed.

delegate void GetAtomFeedCallback(Stream responseStream);

public MainPage()
{
    InitializeComponent();

    SupportedOrientations = SupportedPageOrientation.Portrait |
        SupportedPageOrientation.Landscape;

    string url = "http://yoursite/_vti_bin/listdata.svc/Announcements";
    string username = "username";
    string password = "password";
    string domain = "";

    GetAtomFeed(url, username, password, domain, (s) =>
    {
        XNamespace ns = "
http://www.w3.org/2005/Atom";
        XDocument xdoc = XDocument.Load(s);

        var items = from item in xdoc.Root.Elements(ns + "entry")
                    select new { Title = item.Element(ns + "title").Value };

        this.Dispatcher.BeginInvoke(() =>
        {
            foreach (var item in items)
            {
                MessageBox.Show(item.Title);
            }
        });
    });
}

private static void GetAtomFeed(string url, string username,
    string password, string domain, GetAtomFeedCallback cb)
{
    HttpWebRequest webReq = (HttpWebRequest)HttpWebRequest.Create(url);
    webReq.Credentials = new NetworkCredential(username, password, domain);

    webReq.BeginGetResponse(
        (result) =>
        {
            HttpWebRequest asyncReq = (HttpWebRequest)result.AsyncState;
            HttpWebResponse resp = (HttpWebResponse)asyncReq.EndGetResponse(result);
            cb(resp.GetResponseStream());
        }, webReq);
}

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.

Next week (18th and 19th of January, 2010) the Microsoft SharePoint Connections 2010 will be held in Amsterdam RAI (The Netherlands). There is a great lineup of speakers and sessions over there, so I'm sure it will be a very interesting event! I will be presenting three sessions, one on Monday and two on Tuesday:

  • Client-Side Technologies in SharePoint 2010
  • Silverlight and SharePoint 2010: Better Together
  • Advanced Web Part Development in SharePoint 2010

I'm also very proud to mention that U2U will be sponsering the SharePINT community event on Monday evening. As a Belgian company we are of course buying you guys some real Belgian beer (Leffe)! So make sure to visit the expo area of the conference after the last session on Monday and feel free to say hi. :-)

More Posts « Previous page - Next page »