08 Oct 2010

SharePint @ Tech·Ed 2010!

After a full day of learning new and interesting SharePoint tips, tricks and ideas, come and hang out with fellow SharePoint enthusiasts to help digest your new knowledge and a pint or two of anything else you like.
Hosted by The MOSS Show, with with some prizes to give away, it should be a fun evening for all.
RSVP essential as we need to finalise venue bookings!
Date: Monday, 18 Oct.
Venue: Cubana Durban, 128 Florida Road
Time: 7:00 p.m.
Dress: Collared shirts & smart shoes for gents
Map & Directions from the CCI: View Map
Click to Register Here
A special thanks to our Sponsors:
Sponsors

28 Sep 2010

Upload files to SharePoint using OData!

I posted yesterday about some pain I felt when working with SharePoint and the OData API, to balance the story this post cover some pleasure of working with it – that being uploading a file to document library using OData!

This is really easy to do, once you know how – but it’s the learning curve of Everest here which makes this really hard to get right, as you have both OData specialisations and SharePoint quirks to contend with. The requirements before we start is we need a file (as a stream), we need to know it’s filename, we need it’s content type and we need to know where it will go.

For this post I am posting to a document library called Demo (which is why OData generated the name of DemoItem) and the item is a text file called Lorem ipsum.txt. I know it is a text file, which means I also know it’s Content Type is plain/text.

The code, below, is really simple and here are what is going on:

  • Line 1: I am opening the file using the System.IO.File class, this gives me the stream I need.
  • Line 3: To communicate with the OData service I use the DataContext class which was generated when I added the service reference to the OData service and passed in the URI to the OData service.
  • Line 8: Here I create a DemoItem - remember in SharePoint everything is a list or a list item, even a document which means I need to create the item first. I set the properties of the item over the next few lines. It is vital you set these and set them correctly or it will fail.
  • Line 16: I add the item to the context, this means that it is being tracked now locally – it is not in SharePoint yet. It is vital that this be done prior to you associating the stream.
  • Line 18: I associate the stream of the file to the item. Once again, this is still only happening locally – SharePoint has not been touched yet.
  • Line 20: SaveChanges handles the actual writing to SharePoint.
using (FileStream file = File.Open(@"C:\Users\Robert MacLean\Documents\Lorem ipsum.txt", FileMode.Open))
{
    DataContext sharePoint = new DataContext(new Uri("http://<sharepoint>/sites/ATC/_vti_bin/listdata.svc"));                

    string path = "/sites/ATC/Demo/Lorem ipsum.txt";
    string contentType = "plain/text";
    DemoItem documentItem = new DemoItem()
    {
        ContentType = contentType,
        Name = "Lorem ipsum",
        Path = path,
        Title = "Lorem ipsum"
    };

    sharePoint.AddToDemo(documentItem);

    sharePoint.SetSaveStream(documentItem, file, false, contentType, path);

    sharePoint.SaveChanges();
}

Path Property

The path property which is set on the item (line 12) and when I associate the stream (line 18, final parameter) is vital. This must be the path to where the file will exist on the server. This is the relative path to the file regardless of what SharePoint site you are in for example:

  • Path: /Documents/demo.txt
    • Server: http://sharepoint1
    • Site: /
    • Document Library: Documents
    • Filename: demo.txt
  • Path: /hrDept/CVs/abc.docx
    • Server: http://sharepoint1
    • Site: /hrDept
    • Document Library: CVs
    • Filename: abc.docx

Wrap-up

I still think you need to still look at WebDav as a viable way to handle documents that do not have metadata requirements, but if you have metadata requirements this is a great alternative to the standard web services.

27 Sep 2010

Cannot add a Service Reference to SharePoint 2010 OData!

SharePoint 2010 has a number of API’s (an API is a way we communicate with SharePoint), some we have had for a while like the web services but one is new – OData. What is OData?

The Open Data Protocol (OData) is a Webprotocol for querying and updating data that provides a way tounlock your data and free it from silos that exist in applicationstoday. OData does this by applying and building upon Webtechnologies such as HTTP, Atom PublishingProtocol (AtomPub) and JSON toprovide access to information from a variety of applications,services, and stores.

The main reason I like OData over the web services is that it is lightweight, works well in Visual Studio and works easily across platform, thanks to all the SDK’s.

Clipboard01SharePoint 2010 exposes these on the following URL http(s)://<site>/_vti_bin/listdata.svc and you can add this to Visual Studio to consume using the exact same as a web service to SharePoint, right click on the project and select Add Service Reference.

Once loaded, each list is a contract and listed on the left and to add it to code, you just hit OK and start using it.

Add Service Reference Failed

Clipboard03The procedure above works well, until it doesn’t and oddly enough my current work found a situation which one which caused the add reference to fail! The experience isn’t great when it does fail – the Add dialog closes and pops back up blank! Try it again and it disappears again but stays away.

Clipboard04If you check the status bar in VS, you will see the error message indicating it has failed – but by this point you may see the service reference is listed there but no code works, because the adding failed.

If you right click and say delete, it will also refuse to delete because the adding failed. The only way to get rid of it is to close Visual Studio, go to the service reference folder (<Solution Folder>\<Project Folder>\Service References) and delete the folder in there which matches the name of your service. You will now be able to launch Visual Studio again, and will be able to delete the service reference.

What went wrong?

Clipboard06Since we have no way to know what went wrong, we need to get a lot more low level. We start off by launching a web browser and going to the meta data URL for the service: http(s)://<site>/_vti_bin/listdata.svc/$metadata

In Internet Explorer 9 this just gives a useless blank page Sad smile but if you use the right click menu option in IE 9, View Source, it will show you the XML in notepad. This XML is what Visual Studio is taking, trying to parse and failing on. For us to diagnose the cause we need to work with this XML, so save it to your machine and save it with a .csdl file extension. We need this special extension for the next tool we will use which refuses to work with files without it.

Clipboard07The next step is to open the Visual Studio Command Prompt and navigate to where you saved the CSDL file. We will use a command line tool called DataSvcUtil.exe. This may be familiar to WCF people who know SvcUtil.exe which is very similar, but this one is specifically for OData services. All it does is take the CSDL file and produce a code contract from it, the syntax is very easy: datasvcutil.exe /out:<file.cs> /in:<file.csdl>

Immediately you will see a mass of red, and you know that red means error. In my case I have a list called 1 History which in the OData service is known by it’s gangster name _1History. This problem child is breaking my ability to generate code, which you can figure out by reading the errors. 

Solving the problem!

Clipboard09Thankfully I do not need 1 History, so to fix this issue I need to clean up the CSDL file of _1History references. I switched to Visual Studio and loaded the CSDL file in it and begin to start removing all references to the troublemaker. I also needed to remove the item contract for the list which is __1HistoryItem. I start off by removing the item contract EntityType which is highlighted in the image along side.

The next cleanup step is to remove all the associations to __1HistoryItem.

Clipboard10Finally the last item I need to remove is the EntitySet for the list:

BREATH! RELAX!

Ok, now the hard work is done and so I jump back to the command prompt and re-run the DataSvcUtil tool, and it now works: Clipboard12

Clipboard14This produces a file, in my case sharepoint.cs, which I am able to add that to my project just as any other class file and I am able to make use of OData in my solution just like it is supposed to work!

26 Aug 2010

Next time on Information Worker

IWLogoText

If you follow the IW website you may have seen that the September community meeting in Jo’burg would be about SharePoint 2010 Deployments. That has changed to something far more exciting: Double Demo Day!

Double Demo Day means we get to see two members of the community do a demo of something very interesting.The demos are:

Creating Workflows with SharePoint Designer 2010, InfoPath and Visio

Creating workflows with Visio 2010 and SharePoint Designer 2010 has never been easier. In this session I’ll go through the process of rapidly creating and deploying workflows in a SharePoint 2010 environment.

This will be presented by Ridwan Sassman, who helped us out last month with video taping the session.

Branding SharePoint 2010 with MasterPages, Layouts and CSS

One of the largest limitations of WSS3.0 and MOSS2007 is the ability to brand SharePoint without intricate knowledge of the platform and in some cases breaking a few rules and modifying out of the box system files to get the desired look and feel. Come and see how the theming engine in SharePoint 2010 together with CSS, Master Pages and Layouts can be used to brand your SharePoint site using the amazing new SharePoint Designer 2010.

This will be presented by Brent Samodien. If you have been to a SLAB’s you will know Brent as he helps us with the venue!

October

Looking ahead to October – there is no Jo’burg community meeting. Why? ‘cause we will all be at Tech·Ed Africa 2010! If you haven’t registered then you must do so NOW! Or you could try and win a free entry!

24 Aug 2010

Tech·Ed Africa 2010: Want to go for free?

Win 1 of 4 Tickets to Microsoft Tech·Ed Africa 2010 worth R6 150 each!!!

Venue:    ICC Durban

Date:       17th - 20th October 2010

All you need to do is take a photo of a Microsoft Tag in a really cool/funny/practical place and upload the picture to the Facebook competition page.

More details in the competition animated video here.

Full Competition Rules on our Facebook page.

Dates for Submissions & Announcements of Winners:

  • 25 Aug 2010    -    Last Date For Submissions (week 1) (5pm)
  • 27 Aug 2010    -    Week 1 Winner Announced
  • 01 Sep 2010    -    Last Date For Submissions (week 2) (5pm)
  • 03 Sep 2010    -    Week 2 Winner Announced
  • 08 Sep 2010    -    Last Date For Submissions (week 3) (5pm)
  • 10 Sep 2010    -    Week 3 Winner Announced
  • 15 Sep 2010    -    Last Date For Submissions (week 4) (5pm)
  • 17 Sep 2010    -    Week 4 Winner Announced

Submissions & Announcements of Winners:

  • A new winner will be selected weekly.
  • Last date for submissions for a particular week is 5pm Wednesday of that week.
  • Winner for that week will be announced on the Friday.
  • Submissions after 5pm will count towards the following week.
  • Submissions which did not win in a previous week will still be considered in following weeks and need not be re-submitted.
  • A person can only win once, thereafter all his other submissions will be ignored.
  • You cannot submit on behalf of another person.
  • Submissions are done by posting a photo to the Facebook page wall.

Terms and Conditions apply:

This competition is limited to Tech·Ed Africa 2010 entrance and does not include Travel, hotel or any other expenses. You will be required to help out at the Developers Community Lounge at Tech·Ed Africa 2010 for 3 hours a day if you do win. For Full list of rules please consult the Facebook page.

20 Aug 2010

It's Dev4Dev's time again!

My favourite gathering of developers happens 2 or 3 times a year, it’s called Dev4Devs. This is a free event which Microsoft runs, where ANYONE can present a topic but they only have 20min! This means that in a morning you see 7 topics and rather than getting swamped in all the details you dive directly to the really important parts.

The topic list is below, and there is some exciting topics there and even some non-MS technology is covered too!

I am also really glad that the entire ATC team at BB&D, which is the team I work in, is presenting – they are highlighted in the list below!

The next one comes on the 4th September 2010 and it occurs at Microsoft’s offices in Johannesburg and you can register at https://msevents.microsoft.com/CUI/EventDetail.aspx?EventID=1032456806&Culture=en-ZA

Session List for Dev4Devs

Windows Phone 7 - Getting Started

A high level introduction to getting started with Windows Phone 7 development including: where to begin, options for developers, thinking about design and a demonstration application.

Presenter: Johannes van Schalkwyk

Making MVVM easy

Starting with WPF, Silverlight or WP7? Heard of MVVM but think it’s WAY too complex for your simple application? Join me for a crash course using the easiest MVVM framework available… Caliburn.Micro!
Presenter: Rudi Grobler (ATC Team Member)

Why you should care about Google Closure

Closure is a modularised set of JavaScript libraries that can assist you in building rich internet applications.

It's been battle-tested by Google on sites like: Gmail, Google Docs and Google Maps.

Attend this short intro to get an understanding of how important these libraries are and why you should consider using them in your next big internet app.

Presenter: Simon Stewart

Introducing NHibernate 3

The daddy of .NET ORM is back with a new release, in this session you'll see a few of the newest features - such as a full IQueryable LINQ provider - that makes NHibernate 3 the best release yet!
Presenter: Kevin McKelvin

Branding SharePoint 2010 with MasterPages, Layouts and CSS

One of the largest limitations of WSS3.0 and MOSS2007 is the ability to brand SharePoint without intricate knowledge of the platform and in some cases breaking a few rules and modifying out of the box system files to get the desired look and feel. Come and see how the theming engine in SharePoint 2010 together with CSS, Master Pages and Layouts can be used to brand your SharePoint site using the amazing new SharePoint Designer 2010.
Presenter: Brent Samodien

Unit Testing - Code Coverage & Mocking

In this presentation William will demonstrate how code coverage tools help measure the effectiveness of your unit tests.  He will also show how Mocking tools can help to add value to your unit tests and ensure that all edge-case logic is properly checked.
Presenter: William Brander (ATC Team Member)

Getting ready for Windows Azure development

Heard about the cloud? Excited about the possibilities? In this session we have a 1000-mile introduction to Microsoft’s operating system for the cloud, Windows Azure, how it compares to the other cloud offerings that are out there and how to get your hands dirty with the skill-up process. Endless possibilities + new tech = fun stuff.
Presenter: Ryno Rijnsburger

An introduction to Mercurial Source Control

Want a quick introduction into a Distributed Version Control System (DVCS)? Meet Mercurial it is a cross-platform, fast, lightweight source control management system designed for easy and efficient handling of distributed projects.
Presenter: Zayd Kara (ATC Team Member)

Making money with Coded UI

Coded UI is a brand new feature of Visual Studio 2010 which enables you to quickly build automated user interface tests for your application and run them as if they were unit tests. In the talk we will look at how Coded UI can change your life, one UI at a time!
Presenter: ME! (ATC Team Member)

Hack .Net in 10 Seconds - Why obfuscation is critical

Hacking 101 – I demonstrate how to bypass basic copy protection in an unobfusctaed .Net application through reverse engineering and show how obfuscation adds a layer of protection. I also demonstrate additional techniques for protecting your applications from hacking once they are released in the wild.
Presenter: Mark Pearl

Composite Applications with PRISM

In this session Stephan will demonstrate how to leverage the Composite Application Libraries to create modularized applications for WPF and Silverlight. He will also show you how to do multi-targeted development by sharing lots of code between the web and desktop applications.
Presenter: Stephan Johnson

An Introduction to Pex and Moles

An introduction into Pex and Moles, covering the basics of Mole Types and Mole Stubs and Parameterised Testing.
Presenter: Dave Russell

ASP.NET Dynamic Data

I will briefly introduce ASP.NET Dynamic Data by showing how to build a complete data maintenance web application with almost zero code.

Moving on, I will demonstrate some standard ways of customising a Dynamic Data application, and some more advanced non-standard customisation techniques. I will finish off by illustrating how Dynamic Data libraries and controls can be leveraged in other applications that don't normally use dynamic data.

Presenter: Brady Kelly

ASP.NET MVC 3

As you probably already surmised, ASP.NET MVC 3 is the next major release of ASP.NET MVC. Join us as we highlight the upcoming features and modifications to this popular framework.
Presenters: Jaco Pretorius and Kobus Brummer

22 Jul 2010

ALM in 2010

Here is the slides from my talk on Application Lifecycle Management in 2010 which I did for the Information Worker user group.

Here is the blurb for the session

Development is not just about writing code and pressing compile. It is a process, which starts long before code is written and extends long after the compile is done and this process includes a lot of management - this process is called Application Lifecycle Management (ALM).

SharePoint development is not immune to this and this presentation looks at what the landscape and tools are like for ALM in 2010 and how it relates to SharePoint development.

You can download the slides and the white paper from the IW site.
10 Jun 2010

How to create an adapter for the TFS Integration Platform - Appendix 2: SimpleDictionary

Note: This post is part of a series and you can find the rest of the parts in the series index.

For my WI adapter I needed an implementation of Dictionary<T,V> which could be serialised and unfortunately the .NET one can’t. So I threw together a simple implementation of one using two List<T>. It is not perfect for every possible time you may need an alternative to Dictionary<T,V>, for example the only item manipulation I have is to add an item and clear all items, but it is great for my needs in the case:

[XmlRoot("simpleDictionary")]
public class SimpleDictionary<Key, Value> : IEnumerable, IXmlSerializable
{
    private List<Key> keys = new List<Key>();
    private List<Value> values = new List<Value>();

    public List<Key> Keys
    {
        get
        {
            return keys;
        }
    }

    public List<Value> Values
    {
        get
        {
            return values;
        }
    }

    public IEnumerator GetEnumerator()
    {
        return (IEnumerator)new SimpleDictionaryEnumerator(this);
    }

    public void Add(Key key, Value value)
    {
        keys.Add(key);
        values.Add(value);
    }

    public void Add(object o)
    {
        KeyValuePair<Key, Value>? keyValuePair = o as KeyValuePair<Key, Value>?;
        if (keyValuePair != null)
        {
            this.Add(keyValuePair.Value.Key, keyValuePair.Value.Value);
        }
    }

    public void Clear()
    {
        keys.Clear();
        values.Clear();
    }

    #endregion

    private class SimpleDictionaryEnumerator : IEnumerator
    {
        private SimpleDictionary<Key, Value> simpleDictionary;
        private int index = -1;

        public SimpleDictionaryEnumerator(SimpleDictionary<Key, Value> simpleDictionary)
        {
            this.simpleDictionary = simpleDictionary;
        }

        #region IEnumerator Members

        public object Current
        {
            get
            {
                return new KeyValuePair<Key, Value>(simpleDictionary.keys[index], simpleDictionary.values[index]);
            }
        }

        public bool MoveNext()
        {
            index++;
            return !(index >= simpleDictionary.keys.Count);

        }

        public void Reset()
        {
            index = -1;
        }
    }

    public System.Xml.Schema.XmlSchema GetSchema()
    {
        return null;
    }

    public void ReadXml(XmlReader reader)
    {
        if (reader.IsEmptyElement)
        {
            return;
        }

        XmlSerializer keySerialiser = new XmlSerializer(typeof(Key));
        XmlSerializer valueSerialiser = new XmlSerializer(typeof(Value));

        reader.Read();
        while (reader.NodeType != System.Xml.XmlNodeType.EndElement)
        {
            reader.ReadStartElement("keyValuePair");

            reader.ReadStartElement("key");
            Key key = (Key)keySerialiser.Deserialize(reader);
            reader.ReadEndElement();

            reader.ReadStartElement("value");
            Value value = (Value)valueSerialiser.Deserialize(reader);
            reader.ReadEndElement();

            this.Add(key, value);

            reader.ReadEndElement(); // for keyvaluepair
            reader.MoveToContent();
        }

        reader.ReadEndElement(); // for root
    }

    public void WriteXml(XmlWriter writer)
    {
        XmlSerializer keySerialiser = new XmlSerializer(typeof(Key));
        XmlSerializer valueSerialiser = new XmlSerializer(typeof(Value));

        for (int counter = 0; counter < this.keys.Count; counter++)
        {
            writer.WriteStartElement("keyValuePair");

            writer.WriteStartElement("key");
            keySerialiser.Serialize(writer, this.keys[counter]);
            writer.WriteEndElement();

            writer.WriteStartElement("value");
            valueSerialiser.Serialize(writer, this.values[counter]);
            writer.WriteEndElement();

            writer.WriteEndElement();

        }
    }
}

Pages