View other SharePoint posts...

I wrote recently of being tasked with the setting up of a SharePoint Development Environment (henceforth known as an SDE). Please refer to that blog post for some good links on this topic by other bloggers. I make no claim to expertise in this area since not even the experts can agree ;-) However, I did manage to successfully create my own SDE over the weekend and I am near to completing my original task of creating a VM that can be distributed among a team of developers and joined to a domain.

Microsoft recommends developing locally using virtual machines. For SharePoint development, one has to develop on the Windows Server O/S. The only practical way to do this locally is to install Windows Server 2003 on a virtual machine. This allows the developer to work independently and compile, test and debug as normal.

Shopping List:

  * Plentiful Dry Martini and Olives
  * Cheap External Drive - USB 2.0
  * Free Windows Server 2003 Standard SP1
  * Free trial - VMWare Workstation 6
  * Free trial - vOptimizer
  * Free 6 Month Trial - Visual Studio 2005 Standard (Professional for Office work)
  * Free 6 Month Trial - SQL Server 2005 (Express won't cut it)
  * Free Trial - Office 2007
  * Free Trial - SharePoint Designer (FrontPage on steroids - put it on your host PC)

I chose VMWare because it is much faster that Virtual PC and has a much better interface. Although it costs $189, I plan on purchasing my own copy to play around with Orcas, Silverlight, etc. We need our toys. If you have an MSDN subscription, then you're laughing. If not, then follow my budget download list above (ok, leave out the Martini). The list above is intended for the developer learning the SharePoint object model on a standalone machine. The MOSS install will be the "Complete" option; that is to say that everything will be part of a small virtual farm with a full version of SQL Server 2005.

I have slipped, stumbled and fell many times trying to piece this mish-mash of a development platform together. Over the coming posts I will try to highlight the steps I took to create a champagne VM on a beer budget and some of the pitfalls I encountered along the way. The next post will outline the VM strategy. Stay tuned!

Events and Delegates - Part II

by agrace 8. September 2007 09:24

Hungry Geek You can read part one of this topic here. This part presents a simple example of how to publish and subscribe to an event that does not send data. Note that events such as button clicks, that generate no data can avail of the EventHandler delegate provided in the class library.

Publish an Event - Five Steps:

* Define type inherited from EventArgs to contain any event-related data. If there is no data, use pre-defined EventArgs type

* Define delegate that specifies prototype of event handler. If the events generates no data, use pre-defined EventHandler delegate

* Define an event based on the delegate type

* Define a protected, virtual method to raise the event

* When the event occurs, call the protected, virtual method above

class ButtonPublisher
     public delegate void EventHandler(object sender, EventArgs e);
     public event EventHandler Click;

     // Each class that publishes an event provides a
     // protected, virtual method to raise that event.
     // The "On" name prefix makes this easy to spot.
     protected void OnClick()
         // Check for subscibers
         if (Click != null)
             // Notify them
             Click(this, null);

     // Raise the event
     public void PerformClick()


Subscribe to an Event - Three Steps:

* Implement an event handler with same signature specified by the event's delegate object

* Create a delegate object specified for the event. This delegate refers to the event handler method (see below)

this.Click += new EventHandler(ButtonClick_Handler);


* Subscribe to event by attaching event handler to the event (see above). Use the += operator so as not to cancel any previously registered delegates

class Subscriber
     static void Main(string[] args)
         ButtonPublisher button = new ButtonPublisher();
         // Create new delegate object and subscribe to event
         button.Click += new ButtonPublisher.EventHandler(ButtonClick_Handler);

     static public void ButtonClick_Handler(object sender, EventArgs e)
         Console.WriteLine("Button Clicked");

         // Keep console window open long enough to read!


Happy coding!

Tags: ,


Events and Delegates - Part I

by agrace 1. September 2007 09:46

This is part one of a series of posts on events and delegates, a powerful means of implementing loosely-coupled designs. This part will focus on delegates. You can read part two here.


As a developer, I think it took me longer than necessary to get my head around the code details of the event/delegate paradigm. In retrospect, I believe this was mainly due to my lack of understanding of the delegate type, which connects everything together.

Another problem I encountered was a lack of consistency of language and definitions used by the authors of books and articles on events and delegates. More on this later.

Publishers + Subscribers = Observer Pattern


There is no need to have a PhD in anonymous methods, function pointers, multicast versus single cast delegates and the like, in order to get started with events. What you do need is a basic understanding of the central piece of the jigsaw: the delegate. Next, you need to get an overview of the Publish-Subscribe model. Finally, you need to open up your code editor and create a basic event sample for yourself.


Generally, delegates (or callbacks) are typesafe pointers to methods, similar to function pointers in C++. We can use delegates to specify callbacks and also to register handlers for GUI events like button clicks. Unlike function pointers, which can only contain the address of a static method, a delegate can refer to instance methods in classes - this is what makes them tremendously useful. A delegate is like an interface: the difference is that the delegate declares a single static or reference method, whereas the interface can declare several methods. Whenever we want classes to communicate with less coupling than with an interface, we should use a delegate. In other words, delegates are not only for use with events!

If we need to specify an action or method in advance and we don't know which method, or even object, that will perform this action, we should use a delegate. For example, we can connect a button to a delegate and at runtime we can resolve that delegate to a particular method to be run.


A delegate is a special type in .NET whose main role in life is to hold a reference to a method. Delegates are defined with a signature, much like methods, and can only hold a reference to a method which matches this signature. We declare a delegate by using the "delegate" keyword and specifying the signature of the method to which it holds a reference. The following is a declaration of a delegate that can reference a method that takes two parameters and does not return a value:

public delegate void EventHandler(object sender, EventArgs e);


The delegate is a TYPE; think of the entire statement above as a type. A method matching this signature would look like this:

public void Button_Clicked(object sender, EventArgs e);


In the following example, the delegate called SampleDelegate can invoke any method that is passed a string parameter and returns an int:

delegate int SampleDelegate(sting str);


We can now initialize a new delegate, like so...

SampleDelegate del = new SampleDelegate(DoSomething);


 ... and can call the delegate as follows:




A final point regarding terminology. When we talk about classes, we use two separate terms: class and object. With delegates, there is only a single term. An instance of a delegate class is also known as a delegate. So, we need to pay attention to context here. I will come back to the issue of terminology in the next post which will focus on events.

Tags: ,