EWS Managed API - Accessing Extended Properties (C#)

by Iphelion - Andy 22. May 2011 10:56

Meed to get at an item's extended properties in Exchange 2007/2010 using .NET?  well here's how...

During a recent engagement a requirement to access extended properties of an exchange item arose when using Exchange 2007 SP1.  I thought I would share with you the method I used to retrieve these properties in case it is something you ever need to do.

In the example below, we will be searching for extended properties for an exchange contact item (to be specific title - i.e. Mr/Mrs/Dr/Professor) which is not returned as part of the properties when a search is performed.  

I have put all the code in a method you can put behind a button in a windows forms application to test,  it obviously requires a reference to the EWS API DLLs and you will need an account that has permission to connect and do relevant searches.  The code is commented to help you through step by step and there is a reference at the end containing a list of all extended properties that you should be able to retrieve from exchange..  enjoy..

 

// first place some includes at the top of your class or form
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;

using Microsoft.Exchange.WebServices.Autodiscover;
using Microsoft.Exchange.WebServices.Data;
using Microsoft.Exchange.WebServices.Dns;

public void GetContacts()
{
	// first declare the exchange object
	private ExchangeService exch = new ExchangeService(ExchangeVersion.Exchange2007_SP1);

	// now we have to create a definition for the extended property we want to return
	ExtendedPropertyDefinition titleProperty = new ExtendedPropertyDefinition(0x3A45, MapiPropertyType.String);  

	// specify your exchange server
	exch.Url = new Uri("https://<yourserver>/EWS/Exchange.aspx");

	// specify credentials to use when accessing exchange if not the logged in user
        exch.UseDefaultCredentials = false;
        exch.Credentials = new NetworkCredential("<USERNAME>", "<PASSWORD>", "<DOMAIN>");

	// now we need to create a property set which contains a list of properties we wish to retrieve from exchange
	// above and beyond the first-class properties (i.e. the pre-defined properties on the object)
	PropertySet ps = new PropertySet(BasePropertySet.FirstClassProperties) { titleProperty };

	
	// next we define the folder we wish to search for items - in this case the contacts folder
	FolderId folder = WellKnownFolderName.Contacts;

	// now we need an ItemView object to store the results of the search we plan to do and we also need
	// to define the propertyset of this view to our previously created PropertySet object to tell the 
	// API that we want to bring back additional properties in this view when the search is executed
        FindItemsResults<Item> result = new ItemView(1000);
        itemview.PropertySet = ps;	

	// Next we want to load the additional properties in the result set according to our PropertySet definition
	// which is done by calling the LoadPropertiesForItems method on the exchange connector object
	exch.LoadPropertiesForItems(result, ps);

	// if we have some results ...
	if (result.TotalCount > 0)
	{
		// loop through each item returned from the search 
		foreach (Item i in result)
		{
			// cast the item to a contact objec to get at the first-class properties.
			Contact c = (Contact)i;
			// lets set up a string to hold our title value inside the loop
			string titleValue = string.empty;

			// now we use the items TryGetProperty method passing in our property definition and our
			// the variable we would like to populate if there is a value to be returned
			i.TryGetProperty(titleProperty, titleValue);

			// if titlevalue is not null then display it in a messagebox, otherwise show a blank messagebox
			MessageBox.Show(titleValue != null ? titleValue : String.Empty);
		}
	}

	// indicate the end of the loop to the user
	MessageBox.Show("Complete!");
}

 

Extended properties ref:  http://msdn.microsoft.com/en-us/library/gg274394(v=exchg.80).aspx

Office 2010 features for legal

by Iphelion - Andy 11. March 2011 10:52

Well its that time again, and legal firms in the UK are fast approaching decision time on how to takle the long and winding road that leads to the latest Microsoft Office offering.  Having personally spoken to a cross section of firms over the last few weeks, I thought it would be good to write an overview article on the common conversation items and cover a few of the things that the new version of word has to offer in terms of the legal industry.  I plan to delve into each of the items in a bit more detail over the coming weeks as and when I get some time to do so..  

So without further ado..

What is in Office 2010 that is relevant to legal and how will it save me time and/or money across the firm?

So lets start with a couple of potential money savers...

  • Document Comparison:  Word 2010 has document comparison functionality and while it may not be as detailed as some of the other products available, it may very well suffice for the majority of users if you were out to cut down licences on third party products.  I only managed to find a Video of this feature in Office 2007 -
    http://www.youtube.com/watch?v=k1J19uluI5U
  • PDF Rendition:  Office now comes with the ability to produce PDFs nativley, so no need for software like PDF995 any more..
    http://www.youtube.com/watch?v=Y_n0EUST6T0
  • Meta-Data Stripping:  Office now comes with the ability to strip out any potentially dangerous meta-data within documents as well so more potential licence savings if you use third party meta-data stripping tools/servers.
    http://www.youtube.com/watch?v=mfVQ7g28tA0

Now onto the features that might save you a bit of time

  • The 2010 Ribbon:  The ribbon in 2010 is not hugely different to 2007 but now allows for more extensive customisation than before.. http://office.microsoft.com/en-us/support/office-video-FX102493438.aspx 
  • Styles Gallery:  Finally we get a style gallery that can hide and re-order styles shown to the user meaning you can have much greater control over the documents that are created within your firm and reduce the risk of corruption
    Video here

And some changes from pre Office 2007..

  • Navigation pane:  A quick and easy way to navigate your large documents has been introduced called the navigation pane,  see it in action here
  • Building Blocks:  Create, store and manage sections of content for constructing documents within Word  .. check them out in Word 2007 http://www.youtube.com/watch?v=EyzAqQ7D6mk  

And here are some features that microsoft are making some noise about...

  • Document Co-Authoring:  Using SharePoint 2010 as a back-office server, you can now (should you want to) enable people to work on the same document at the same time (i.e. two cursors typing in the same document) - 
    http://office.microsoft.com/en-us/word-help/video-coauthoring-in-word-2010-VA101848883.aspx
  • Sharepoint 2010 Integration:  Microsoft have ramped up their integration with the latest SharePoint offering with Office 2010 and also with the imminent release of Office 365 (and things like SkyDrive) to the small business and home market basic document management principles are being introduced to a much wider audience these days.
    Video here 

About the authors

Iphelion are a software company who specialise in document automation and productivity tools for the legal market and are sought after for their professional services. Iphelion work with all sizes of firm from boutique to magic-circle.

Having worked with some of the top global law firms, they have the knowledge and experience to offer their clients invaluable business analysis advice, system integration and superior products.

Iphelion believe that a good working relationship is the key to a successful company and will always strive to offer the upmost integrity and professionalism coupled with a personal and loyal service.