<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>House of Metnetsky &#187; vsto</title>
	<atom:link href="http://cowarthill.com/blog/index.php/tag/vsto/feed/" rel="self" type="application/rss+xml" />
	<link>http://cowarthill.com/blog</link>
	<description>Run Tortoise Run</description>
	<lastBuildDate>Fri, 26 Feb 2010 17:15:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>VSTO Outlook Add-ins &#8211; Reference Leaks</title>
		<link>http://cowarthill.com/blog/index.php/2010/01/01/vsto-outlook-add-ins-reference-leaks/</link>
		<comments>http://cowarthill.com/blog/index.php/2010/01/01/vsto-outlook-add-ins-reference-leaks/#comments</comments>
		<pubDate>Fri, 01 Jan 2010 16:51:20 +0000</pubDate>
		<dc:creator>MET</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[kmbs]]></category>
		<category><![CDATA[vsto]]></category>

		<guid isPermaLink="false">http://cowarthill.com/blog/?p=359</guid>
		<description><![CDATA[Not too long ago I came across an annoying issue with my Outlook Add-in which creates a form region at the bottom of the contact and distribution list inspector windows. Apparently, if you edit certain fields (like check-boxes) when a VSTO add-in is loaded the reference count is not properly decremented which leaves the OutlookItem in [...]]]></description>
			<content:encoded><![CDATA[<p>Not too long ago I came across an annoying issue with my Outlook Add-in which creates a form region at the bottom of the contact and distribution list inspector windows. Apparently, if you edit certain fields (like check-boxes) when a <a href="http://blogs.msdn.com/vsto/" target="_blank">VSTO</a> add-in is loaded the reference count is not properly decremented which leaves the <a href="http://msdn.microsoft.com/en-us/library/microsoft.office.interop.outlook.contactitem.aspx" target="_blank">OutlookItem</a> in an edited state.</p>
<p>To fix the issue you have to edit some auto-generated <a href="http://blogs.msdn.com/vsto/" target="_blank">VSTO</a> code and release the <a href="http://msdn.microsoft.com/en-us/library/microsoft.office.interop.outlook.contactitem.aspx" target="_blank">OutlookItem</a> during a setup event like so:</p>
<pre class="brush: csharp;">
private void RegionFactory_FormRegionInitializing(object sender, Outlook.FormRegionInitializingEventArgs e)
{
    Marshal.ReleaseComObject(e.OutlookItem);
}
</pre>
<p>This block of code can be found in the region block labeled: <strong>#region Form Region Factory</strong></p>
<p>Apparently, a Microsoft <a href="http://blogs.msdn.com/pcreehan/default.aspx" target="_blank">support engineer</a> posted about this back in <a href="http://blogs.msdn.com/pcreehan/archive/2008/08/07/form-region-leak-in-visual-studio-tools-for-office-2008-v3-template.aspx" target="_blank">August of 2008</a>, but I never came across it until after working with a different very nice MSDN support engineer.</p>
<p>The other day however, I realized that the trick above does not in fact work for Distribution List (<a href="http://msdn.microsoft.com/en-us/library/bb157886.aspx" target="_blank">IPM.DistList</a>) form regions. Watch the following video for proof!</p>
<div class="aligncenter">
[See post to watch Flash video]
</div>
<p>I contacted the very nice engineer who helped me before to re-open/create a support ticket about the issue. While waiting for a response however, I kept trying to fix the issue and finally did. I&#8217;m quite hopeful that my fix is not the best answer, as it&#8217;s truly a bizarre hack.</p>
<p>Take a look at the Designer code generated for your region. The <a href="http://msdn.microsoft.com/en-us/library/microsoft.office.tools.outlook.iformregionfactory.aspx" target="_blank">IFormRegionFactory</a> which creates an instance of the actual ImportedFormRegion does not need to return anything for the region to load. In fact, if you throw an exception from <a href="http://msdn.microsoft.com/en-us/library/microsoft.office.tools.outlook.iformregionfactory.createformregion.aspx" target="_blank">IFormRegionFactory.CreateFormRegion</a>, the <a href="http://msdn.microsoft.com/en-us/library/microsoft.office.interop.outlook.distlistitem.aspx" target="_blank">DistListItem</a> is properly unreferenced when the inspector is closed.</p>
<p>You can watch the following video to see it in action!</p>
<div class="aligncenter">
[See post to watch Flash video]
</div>
]]></content:encoded>
			<wfw:commentRss>http://cowarthill.com/blog/index.php/2010/01/01/vsto-outlook-add-ins-reference-leaks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://cowarthill.com/blog/wp-content/uploads/2009/12/dist-bad.flv" length="16759864" type="video/x-flv" />
<enclosure url="http://cowarthill.com/blog/wp-content/uploads/2009/12/dist-good.flv" length="67887874" type="video/x-flv" />
<enclosure url="http://cowarthill.com/blog/wp-content/uploads/2009/12/dist-bad.ogg" length="3891624" type="audio/ogg" />
		</item>
		<item>
		<title>VSTO Outlook Add-ins &#8211; Getting Contacts from Distribution Lists</title>
		<link>http://cowarthill.com/blog/index.php/2009/12/29/vsto-outlook-add-ins-distribution-list-recipients/</link>
		<comments>http://cowarthill.com/blog/index.php/2009/12/29/vsto-outlook-add-ins-distribution-list-recipients/#comments</comments>
		<pubDate>Tue, 29 Dec 2009 23:33:06 +0000</pubDate>
		<dc:creator>MET</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[kmbs]]></category>
		<category><![CDATA[vsto]]></category>

		<guid isPermaLink="false">http://cowarthill.com/blog/?p=336</guid>
		<description><![CDATA[A while ago I was tasked with creating an Outlook Add-in that enables a user to opt-in their contacts for synchronization with a KMBS product named Page Scope Enterprise Suite (PSES). Part of this add-in is to offer a panel at the bottom of every contact so they can be opt-ed in for synchronization like [...]]]></description>
			<content:encoded><![CDATA[<p>A while ago I was tasked with creating an Outlook Add-in that enables a user to opt-in their contacts for synchronization with a <a href="http://kmbs.konicaminolta.us/" target="_blank">KMBS</a> product named <a href="http://kmbs.konicaminolta.us/content/products/models/pagescopeenterprise.html" target="_blank">Page Scope Enterprise Suite (PSES)</a>. Part of this add-in is to offer a panel at the bottom of every contact so they can be opt-ed in for synchronization like so:</p>
<p><a href="http://cowarthill.com/blog/wp-content/uploads/2009/12/contact.png"><img class="aligncenter size-medium wp-image-339" title="Outlook Contact Form Region" src="http://cowarthill.com/blog/wp-content/uploads/2009/12/contact-300x218.png" alt="Outlook Contact Form Region" width="300" height="218" /></a></p>
<p>As you can see this isn&#8217;t very fancy &#8211; two check-boxes to control if you want the email and/or fax addresses sent along to PSES. Naturally, there is also an option to opt-in distribution lists:</p>
<p><a href="http://cowarthill.com/blog/wp-content/uploads/2009/12/group1.png"><img class="aligncenter size-medium wp-image-341" title="Outlook Distribution Form Region" src="http://cowarthill.com/blog/wp-content/uploads/2009/12/group1-300x226.png" alt="Outlook Distribution Form Region" width="300" height="226" /></a></p>
<p>This is of course where the fun began. In my personal opinion distribution lists were not properly implemented, or rather updated from earlier versions of Outlook. For instance, take a close look at the image above. Notice how a &#8220;fax&#8221; address is listed under the &#8220;E-mail&#8221; column? Do you also notice how it has the @ symbol? What in the world is going on here?</p>
<p>Another issue is how the ContactItem relates to the Recipient &#8211; or rather how you can obtain the actual contact from the item in the distribution list. Based on documentation we should be able to use the <strong><a href="http://msdn.microsoft.com/en-us/library/microsoft.office.interop.outlook.addressentry.getcontact.aspx" target="_blank">GetContact()</a></strong> method found a little ways down on the <strong><a href="http://msdn.microsoft.com/en-us/library/microsoft.office.interop.outlook.recipient.aspx" target="_blank">Recipient</a></strong> class.</p>
<pre class="brush: csharp;">
Outlook.Recipient.AddressEntry.GetContact()
</pre>
<p>Sadly however, this doesn&#8217;t work (for me at-least) no matter what I did. So after a decent amount of trial and error I was able to determine that a Recipient&#8217;s <strong><a href="http://msdn.microsoft.com/en-us/library/microsoft.office.interop.outlook.recipient.entryid.aspx" target="_blank">EntryID</a></strong> actually contains the the Contact&#8217;s <strong><a href="http://msdn.microsoft.com/en-us/library/microsoft.office.interop.outlook._contactitem.entryid.aspx" target="_blank">EntryID</a></strong>.</p>
<p>For example:</p>
<pre class="brush: csharp;">
Recipient.EntryID = &quot;abcd-1234&quot;;
Contact.EntryID = &quot;1234&quot;;
</pre>
<p>This is simplified of course as real ID&#8217;s are quite long. So to actually get the contact we should do this:</p>
<pre class="brush: csharp;">
Outlook.Recipient r = DistListItem.GetMember(1);
string rid = r.EntryID;
rid = rid.Substring(rid.Length - 48);

Outlook.ContactItem c = Application.Session.GetItemFromID(rid, null) as Outlook.ContactItem;
</pre>
<p>Hopefully someone else will find this mess useful as I couldn&#8217;t find anything a year ago about these oddities and issues.</p>
]]></content:encoded>
			<wfw:commentRss>http://cowarthill.com/blog/index.php/2009/12/29/vsto-outlook-add-ins-distribution-list-recipients/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
