<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Soledad Pano's Blog</title><link>https://weblogs.asp.net:443/spano/</link><description>Just Technical Stuff </description><item><title>Customizing a Sharepoint 2010 Search Center</title><link>https://weblogs.asp.net:443/spano/customizing-a-sharepoint-2010-search-center</link><description>&lt;p&gt;Almost all Sharepoint sites make use of Sharepoint Search Capabilities. Sharepoint also provides OOB site templates for setting up search centers. Today I would like to show how we customized the OOB Basic Search Center site to meet the overall site’s L&amp;amp;F and the customer’s needs. All the customization is done programmatically in a feature event receiver so it can be automatically applied when deploying to the different environments.&lt;/p&gt;  &lt;p&gt;We are creating the Search Center as a subsite of the main site. The OOB Basic Search Center has three pages: Default, Advanced Search and SearchResults. The customization steps consists of:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Create Search Center subsite &lt;/li&gt;    &lt;li&gt;Apply custom master page to search center &lt;/li&gt;    &lt;li&gt;Configure the Web Parts on the Advanced and Search Results Page &lt;/li&gt;    &lt;li&gt;Create custom Metadata Properties, Search Scopes and Search Rules &lt;/li&gt; &lt;/ul&gt;  &lt;h2&gt;Search Center Creation&lt;/h2&gt;  &lt;p&gt;The search center creation is done programmatically on the feature activated event:&lt;/p&gt;  &lt;div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-size: 10pt; border-top: #000080 1px solid; font-weight: bold; border-right: #000080 1px solid; padding-top: 2px"&gt;Code Snippet&lt;/div&gt;  &lt;div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid"&gt;   &lt;div style="padding-bottom: 2px; background-color: #ffffff; padding-left: 5px; padding-right: 5px; max-height: 300px; overflow: auto; padding-top: 2px"&gt;     &lt;blockquote&gt;       &lt;p&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; FeatureActivated(&lt;span style="color: #2b91af"&gt;SPFeatureReceiverProperties&lt;/span&gt; properties)           &lt;br /&gt;{           &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #2b91af"&gt;SPSite&lt;/span&gt; site = properties.Feature.Parent &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; &lt;span style="color: #2b91af"&gt;SPSite&lt;/span&gt;;           &lt;br /&gt;          &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #008000"&gt;//create search center subsite&lt;/span&gt;           &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; (&lt;span style="color: #2b91af"&gt;SPWeb&lt;/span&gt; web = site.OpenWeb())           &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {           &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;try&lt;/span&gt;           &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {           &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; web.AllowUnsafeUpdates = &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;;           &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; (&lt;span style="color: #2b91af"&gt;SPWeb&lt;/span&gt; existingSearchCenter = site.AllWebs[&lt;span style="color: #a31515"&gt;&amp;quot;Search&amp;quot;&lt;/span&gt;])           &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {           &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (existingSearchCenter != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt; &amp;amp;&amp;amp; existingSearchCenter.Exists)           &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {           &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; existingSearchCenter.Delete();           &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }           &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }           &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; (&lt;span style="color: #2b91af"&gt;SPWeb&lt;/span&gt; searchCenter = site.AllWebs.Add(&lt;span style="color: #a31515"&gt;&amp;quot;Search&amp;quot;&lt;/span&gt;, &lt;span style="color: #a31515"&gt;&amp;quot;Search&amp;quot;&lt;/span&gt;, &lt;span style="color: #a31515"&gt;&amp;quot;Basic Search Center&amp;quot;&lt;/span&gt;, 1033, &lt;span style="color: #a31515"&gt;&amp;quot;SRCHCENTERLITE#0&amp;quot;&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;))           &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {           &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #008000"&gt;//customize search center&lt;/span&gt;           &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; cust.CustomizeEnterpriseSearchCenter(searchCenter);           &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; searchCenter.Update();           &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #008000"&gt;//set search center in root web:&lt;/span&gt;           &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; web.AllProperties[&lt;span style="color: #a31515"&gt;&amp;quot;SRCH_ENH_FTR_URL&amp;quot;&lt;/span&gt;] = searchCenter.ServerRelativeUrl;           &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #008000"&gt;//set search drowpdown mode&lt;/span&gt;           &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; web.AllProperties[&lt;span style="color: #a31515"&gt;&amp;quot;SRCH_SITE_DROPDOWN_MODE&amp;quot;&lt;/span&gt;] = &lt;span style="color: #a31515"&gt;&amp;quot;HideScopeDD&amp;quot;&lt;/span&gt;;&lt;span style="color: #008000"&gt;//Do not show scopes dropdown, and default to target results page&lt;/span&gt;           &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; web.Update();           &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }           &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }           &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;finally&lt;/span&gt;           &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {           &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; web.AllowUnsafeUpdates = &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;;           &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }           &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }           &lt;br /&gt;}&lt;/p&gt;     &lt;/blockquote&gt;   &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;In order to redirect search results to the Search Results Page on the Search Center sub site, some settings need to be configured on the main site. Under Site Settings - Site Collection Settings - Search Settings, the Search Center is connected to main site: &lt;/p&gt;  &lt;p&gt;&amp;#160; &lt;/p&gt;  &lt;p&gt;&lt;a href="https://aspblogs.blob.core.windows.net/media/spano/Media/image_6BF13F17.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://aspblogs.blob.core.windows.net/media/spano/Media/image_thumb_2902441F.png" width="644" height="301" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;This is what the following lines in the feature receiver do:&lt;/p&gt; &lt;span style="color: #008000"&gt;//set search center in root web:&lt;/span&gt;   &lt;br /&gt;web.AllProperties[&lt;span style="color: #a31515"&gt;&amp;quot;SRCH_ENH_FTR_URL&amp;quot;&lt;/span&gt;] = searchCenter.ServerRelativeUrl;   &lt;br /&gt;&lt;span style="color: #008000"&gt;//set search drowpdown mode&lt;/span&gt;   &lt;br /&gt;web.AllProperties[&lt;span style="color: #a31515"&gt;&amp;quot;SRCH_SITE_DROPDOWN_MODE&amp;quot;&lt;/span&gt;] = &lt;span style="color: #a31515"&gt;&amp;quot;HideScopeDD&amp;quot;&lt;/span&gt;;&lt;span style="color: #008000"&gt;//Do not show scopes dropdown, and default to target results page&lt;/span&gt;&amp;#160;&amp;#160; &lt;h2&gt;Search Master Page&lt;/h2&gt;  &lt;p&gt;The Search Center has some particularities that prevent them to use the same master page as the main site. So a custom master page needed to be provisioned. In order to provide a master page compatible with the page layouts of the OOB Basic Search Center, we follow the instructions provided in this article: &lt;a href="http://blog.drisgill.com/2010/09/converting-custom-sharepoint-2010.html"&gt;Converting a Custom SharePoint 2010 Master Page into a Search Center Master Page&lt;/a&gt;.&lt;/p&gt;  &lt;h2&gt;Advanced Search Page customization&lt;/h2&gt;  &lt;p&gt;The requirements for the advanced search web part, were to hide the language picker, display the scopes picker (with custom scopes, like Articles, News, Audio, Video, etc) and add some custom properties to the “Add property restrictions” filter.&lt;/p&gt;  &lt;p&gt;&lt;a href="https://aspblogs.blob.core.windows.net/media/spano/Media/image_20FA7BF0.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://aspblogs.blob.core.windows.net/media/spano/Media/image_thumb_7EC27069.png" width="644" height="408" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;This customization is performed by the following code:&lt;/p&gt;  &lt;div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid"&gt;   &lt;div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px"&gt;Code Snippet&lt;/div&gt;    &lt;div style="padding-bottom: 2px; background-color: #ffffff; padding-left: 5px; padding-right: 5px; max-height: 300px; overflow: auto; padding-top: 2px"&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; EditAdvancedSearchBoxWebPart(&lt;span style="color: #2b91af"&gt;SPLimitedWebPartManager&lt;/span&gt; manager)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; System.Web.UI.WebControls.WebParts.&lt;span style="color: #2b91af"&gt;WebPart&lt;/span&gt; wp = GetWebPart(manager, &lt;span style="color: #a31515"&gt;&amp;quot;Advanced Search Box&amp;quot;&lt;/span&gt;);       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (wp != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #2b91af"&gt;AdvancedSearchBox&lt;/span&gt; webpart = wp &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; &lt;span style="color: #2b91af"&gt;AdvancedSearchBox&lt;/span&gt;;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (webpart != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; webpart.ShowLanguageOptions = &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; webpart.ShowScopes = &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; webpart.Properties = GetFromResources(&lt;span style="color: #a31515"&gt;&amp;quot;SearchCenter.WebPartsConfig.AdvancedSearchBoxProperties.xml&amp;quot;&lt;/span&gt;);       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; manager.SaveChanges(webpart);       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Even if the code is not complete, you can see what we are doing, editing the page, getting the Advances Search Box web part by name and modifying its properties. We are loading the Properties from an xml file, which includes the custom properties we added for filtering.&lt;/p&gt;  &lt;h2&gt;Custom Managed Properties and Scopes&lt;/h2&gt;  &lt;p&gt;In order to add custom properties and scopes to the Advanced Search Web Part , we first need to create them. The matadata properties are mapped to crawled properties. This means that, when Sharepoint crawls the site content and finds data in a particular list and field, if will create a crawled property for that field. For example, in the image below we can see the 0ws_keywords crawled property mapped to the Keywords Managed Property on the Admin site.&lt;/p&gt;  &lt;p&gt;&lt;a href="https://aspblogs.blob.core.windows.net/media/spano/Media/image_767E2505.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://aspblogs.blob.core.windows.net/media/spano/Media/image_thumb_5A20BD18.png" width="644" height="324" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The creation and mapping of the managed property is done programmatically thru the feature activation event receiver. The crawled property is created by Sharepoint within a crawl, and must exist before activating the feature.&lt;/p&gt;  &lt;p&gt;Here is the code for creating a managed property:&lt;/p&gt;  &lt;div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid"&gt;   &lt;div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px"&gt;Code Snippet&lt;/div&gt;    &lt;div style="padding-bottom: 2px; background-color: #ffffff; padding-left: 5px; padding-right: 5px; max-height: 300px; overflow: auto; padding-top: 2px"&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; CreateManagedProperty(&lt;span style="color: #2b91af"&gt;Schema&lt;/span&gt; schema, &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; managedPropertyName, &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; crawledPropertyCategory, &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; crawledPropertyName)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (!schema.AllManagedProperties.Contains(managedPropertyName))       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #2b91af"&gt;Category&lt;/span&gt; category = schema.AllCategories[crawledPropertyCategory];       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;var&lt;/span&gt; crawledProps = category.QueryCrawledProperties(crawledPropertyName, 1, &lt;span style="color: #2b91af"&gt;Guid&lt;/span&gt;.NewGuid(), &lt;span style="color: #2b91af"&gt;String&lt;/span&gt;.Empty, &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;).Cast&amp;lt;&lt;span style="color: #2b91af"&gt;CrawledProperty&lt;/span&gt;&amp;gt;();       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;var&lt;/span&gt; crawledProp = crawledProps.FirstOrDefault();       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (crawledProp != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #2b91af"&gt;ManagedDataType&lt;/span&gt; managedPropertyType = GetManagedPropertyType(crawledProp);       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #2b91af"&gt;ManagedProperty&lt;/span&gt; managedProperty = schema.AllManagedProperties.Create(managedPropertyName, managedPropertyType);       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;var&lt;/span&gt; mappings = managedProperty.GetMappings();       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; mappings.Add(&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;Mapping&lt;/span&gt;(crawledProp.Propset, crawledProp.Name, crawledProp.VariantType, managedProperty.PID));       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; managedProperty.SetMappings(mappings);       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; managedProperty.Update();       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;For the custom scopes, we are mostly using Property Query rules using the contentclass for the restriction:&lt;/p&gt;  &lt;p&gt;&lt;a href="https://aspblogs.blob.core.windows.net/media/spano/Media/image_0699C732.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://aspblogs.blob.core.windows.net/media/spano/Media/image_thumb_0CD077F3.png" width="644" height="228" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The example of the figure is the rule of the News scope. In this case the news are stored in a list with a custom list definition. Below is the code of the list definition. Look at the Type number: 10314&lt;/p&gt;  &lt;div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid"&gt;   &lt;div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px"&gt;Code Snippet&lt;/div&gt;    &lt;div style="padding-bottom: 2px; background-color: #ffffff; padding-left: 5px; padding-right: 5px; max-height: 300px; overflow: auto; padding-top: 2px"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;?&lt;/span&gt;&lt;span style="color: #a31515"&gt;xml&lt;/span&gt;&lt;span style="color: #0000ff"&gt; &lt;/span&gt;&lt;span style="color: #ff0000"&gt;version&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: #0000ff"&gt;1.0&lt;/span&gt;&amp;quot;&lt;span style="color: #0000ff"&gt; &lt;/span&gt;&lt;span style="color: #ff0000"&gt;encoding&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: #0000ff"&gt;utf-8&lt;/span&gt;&amp;quot;&lt;span style="color: #0000ff"&gt;?&amp;gt;&lt;/span&gt;       &lt;br /&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Elements&lt;/span&gt;&lt;span style="color: #0000ff"&gt; &lt;/span&gt;&lt;span style="color: #ff0000"&gt;xmlns&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: #0000ff"&gt;http://schemas.microsoft.com/sharepoint/&lt;/span&gt;&amp;quot;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;ListTemplate&lt;/span&gt;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;&lt;/span&gt;&lt;span style="color: #ff0000"&gt;Name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: #0000ff"&gt;NewsItemList&lt;/span&gt;&amp;quot;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;&lt;/span&gt;&lt;font style="background-color: #ffff00"&gt;&lt;span style="color: #ff0000"&gt;Type&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: #0000ff"&gt;10314&lt;/span&gt;&amp;quot;         &lt;br /&gt;&lt;/font&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;&lt;/span&gt;&lt;span style="color: #ff0000"&gt;BaseType&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: #0000ff"&gt;0&lt;/span&gt;&amp;quot;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;&lt;/span&gt;&lt;span style="color: #ff0000"&gt;OnQuickLaunch&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: #0000ff"&gt;TRUE&lt;/span&gt;&amp;quot;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;&lt;/span&gt;&lt;span style="color: #ff0000"&gt;SecurityBits&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: #0000ff"&gt;11&lt;/span&gt;&amp;quot;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;&lt;/span&gt;&lt;span style="color: #ff0000"&gt;Sequence&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: #0000ff"&gt;410&lt;/span&gt;&amp;quot;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;&lt;/span&gt;&lt;span style="color: #ff0000"&gt;DisplayName&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: #0000ff"&gt;NewsItemList&lt;/span&gt;&amp;quot;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;&lt;/span&gt;&lt;span style="color: #ff0000"&gt;Description&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: #0000ff"&gt;My List Definition&lt;/span&gt;&amp;quot;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;&lt;/span&gt;&lt;span style="color: #ff0000"&gt;Image&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: #0000ff"&gt;/_layouts/images/itgen.png&lt;/span&gt;&amp;quot;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;       &lt;br /&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt; &lt;span style="color: #a31515"&gt;Elements&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;That is the same number that we are setting the contentclass property to match: STS_ListItem_10314. This means that only items from that list, the news list, will match that scope. This enables to restrict the search to the News scope on the Advanced Search Web Part. In order for that to happen, we also need to include this scope into the Advanced Search display group.&lt;/p&gt;  &lt;h2&gt;Conclusion&lt;/h2&gt;  &lt;p&gt;The code for the complete customization is too much to explain everything here, but the idea was to show how we can make use of the existing Search Center site templates and perform different customizations depending on the project’s requirements. So with little effort we can profit of the OOB advanced search and search results pages that Sharepoint provides.&lt;/p&gt;</description><pubDate>Fri, 20 Jul 2012 21:12:54 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/spano/customizing-a-sharepoint-2010-search-center</guid><category>Sharepoint</category></item><item><title>Where is my Sharepoint 2010 Custom Timer Job running?</title><link>https://weblogs.asp.net:443/spano/where-is-my-sharepoint-2010-custom-timer-job-running</link><description>&lt;p&gt;When building a custom timer job for Sharepoint 2010, special attention should be put on where do we need this job to run. When we have a farm environment, we can choose to run the job on all servers, in one particular server, only the front end servers, etc. Depending on our requirements the timer job implementation and installation approach will change, so we should decide where we want it to run at the first place.&lt;/p&gt;  &lt;p&gt;All Sharepoint timer jobs ultimately inherit from the &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.administration.spjobdefinition.aspx"&gt;SPJobDefinition&lt;/a&gt; class. This class provides 3 constructors:&lt;/p&gt;  &lt;table border="1" cellspacing="0" cellpadding="2" width="522"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="267"&gt;SPJobDefinition()&lt;/td&gt;        &lt;td valign="top" width="253"&gt;Default constructor needed for serialization purposes.&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="267"&gt;SPJobDefinition(String, &lt;strong&gt;SPService&lt;/strong&gt;, SPServer, SPJobLockType) &lt;/td&gt;        &lt;td valign="top" width="253"&gt;Instantiates a timer job associated with the given SPService.&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="267"&gt;SPJobDefinition(String, &lt;strong&gt;SPWebApplication&lt;/strong&gt;, SPServer, SPJobLockType)&lt;/td&gt;        &lt;td valign="top" width="253"&gt;Instantiates a timer job associated with the given SPWebApplication.&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;The first constructor is required for serialization and is for internal use only. One of the other two constructors will be invoked from our custom timer job constructor. The parameters passed to it will define where the timer job will run.&lt;/p&gt;  &lt;p&gt;Here is a sample code of a custom timer job definition: &lt;/p&gt;  &lt;pre class="code"&gt;[&lt;span style="color: #2b91af"&gt;Guid&lt;/span&gt;(&lt;span style="color: #a31515"&gt;&amp;quot;{62FF3B87-654E-41B8-B997-A1EA6720B127}&amp;quot;&lt;/span&gt;)]
&lt;span style="color: blue"&gt;class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;MyTimerJob1 &lt;/span&gt;: &lt;span style="color: #2b91af"&gt;SPJobDefinition
&lt;/span&gt;{
    &lt;span style="color: blue"&gt;public &lt;/span&gt;MyTimerJob1()
        : &lt;span style="color: blue"&gt;base&lt;/span&gt;()
    { }

    &lt;span style="color: blue"&gt;public &lt;/span&gt;MyTimerJob1(&lt;span style="color: blue"&gt;string &lt;/span&gt;name, &lt;span style="color: #2b91af"&gt;SPService &lt;/span&gt;service, &lt;span style="color: #2b91af"&gt;SPServer &lt;/span&gt;server, 
        &lt;span style="color: #2b91af"&gt;SPJobLockType &lt;/span&gt;lockType) : &lt;span style="color: blue"&gt;base&lt;/span&gt;(name, service, server, lockType)
    { }

    &lt;span style="color: blue"&gt;public &lt;/span&gt;MyTimerJob1(&lt;span style="color: blue"&gt;string &lt;/span&gt;name, &lt;span style="color: #2b91af"&gt;SPWebApplication &lt;/span&gt;webApplication, &lt;span style="color: #2b91af"&gt;SPServer &lt;/span&gt;server, 
        &lt;span style="color: #2b91af"&gt;SPJobLockType &lt;/span&gt;lockType) : &lt;span style="color: blue"&gt;base&lt;/span&gt;(name, webApplication, server, lockType)
    { }

    &lt;span style="color: blue"&gt;public override void &lt;/span&gt;Execute(&lt;span style="color: #2b91af"&gt;Guid &lt;/span&gt;targetInstanceId)
    {
        &lt;span style="color: green"&gt;//Execute Timer Job Tasks
    &lt;/span&gt;}
}&lt;/pre&gt;


&lt;p&gt;Besides the required default constructor, we need to provide at least one of the other 2 constructors. Depending on which constructor we use, the timer job definition can be associated either with a service or a web application. It can also be associated with a particular server in the farm and a lock type. So, the first thing is that for a particular server to be eligible to run the job, it must be provisioned with the service or web app associated with the job. Then, if a particular server is passed to the constructor, the job will run only on that server (if it has the associated service or web app, otherwise the job won’t run at all). If no server is associated, then it will run on one or many servers depending on the lock type.&lt;/p&gt;

&lt;p&gt;The &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.administration.spjoblocktype"&gt;SPJobLockType&lt;/a&gt; enumeration can take one of the following values:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;None&lt;/strong&gt;: Provides no locks. The timer job runs on every machine in the farm on which the parent service is provisioned, unless the job I associated with a specified server in which case it runs on only that server (and only if the parent service is provisioned on the server).&lt;/li&gt;

  &lt;li&gt;&lt;strong&gt;ContentDatabase&lt;/strong&gt;: Locks the content database. A timer job runs one time for each content database associated with the Web application.&lt;/li&gt;

  &lt;li&gt;&lt;strong&gt;Job&lt;/strong&gt;: Locks the timer job so that it runs only on one machine in the farm.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So, if we instantiate a timer job passing null as the associated server and None as the lock type, we will expect it to run on every machine in the farm &lt;strong&gt;on which the parent service is provisioned&lt;/strong&gt;. If we passed an SPService to the constructor, we now which service we are talking about, and now on which servers it is provisioned. But, if we passed an SPWebApplication to the constructor, in which servers will the job run? The answer is on every&lt;strong&gt; web font-end server&lt;/strong&gt;, that is the servers where the &lt;strong&gt;Web Application service&lt;/strong&gt; is running on. &lt;/p&gt;

&lt;p&gt;Remember that the different server roles that we can found on a Sharepoint farm are:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Database Server&lt;/strong&gt;: the server that hosts the Microsoft SQL Server database for the farm. Since Sharepoint Foundation is not typically installed in this server, no jobs will run here.&lt;/li&gt;

  &lt;li&gt;&lt;strong&gt;Web Front End Server&lt;/strong&gt;: server where the &lt;em&gt;Microsoft SharePoint Foundation Web Application service&lt;/em&gt; is running on.&lt;/li&gt;

  &lt;li&gt;&lt;strong&gt;Application Server&lt;/strong&gt;: Any other Sharepoint server.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here are a couple of examples on where the jobs will run depending on the parameters passed to the constructor:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: green"&gt;//Job associated with a web app, no server in particular and none lock:
//  will run on all fron end servers.
&lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;jobRunningOnAllFrontEndServers = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;MyTimerJob1&lt;/span&gt;(&lt;span style="color: #a31515"&gt;&amp;quot;mytimerjob&amp;quot;&lt;/span&gt;, 
    &lt;span style="color: #2b91af"&gt;SPWebApplication&lt;/span&gt;.Lookup(webAppURI), &lt;span style="color: blue"&gt;null&lt;/span&gt;, &lt;span style="color: #2b91af"&gt;SPJobLockType&lt;/span&gt;.None);

&lt;span style="color: green"&gt;//Job associated with a web app, one front end server and job lock:
//  will run only in the frontEndServer1 server.
&lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;jobRunningOnAParticularFronEndServer = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;MyTimerJob1&lt;/span&gt;(&lt;span style="color: #a31515"&gt;&amp;quot;mytimerjob&amp;quot;&lt;/span&gt;, 
    &lt;span style="color: #2b91af"&gt;SPWebApplication&lt;/span&gt;.Lookup(webAppURI), fronEndServer1, &lt;span style="color: #2b91af"&gt;SPJobLockType&lt;/span&gt;.Job);

&lt;span style="color: green"&gt;//Job associated with a webApp, and an app server and lock type job: 
//  it won't run on any server since the server specified is NOT running 
//  the Web Application Service
&lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;jobRunningOnNoServer = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;MyTimerJob1&lt;/span&gt;(&lt;span style="color: #a31515"&gt;&amp;quot;mytimerjob&amp;quot;&lt;/span&gt;, 
    &lt;span style="color: #2b91af"&gt;SPWebApplication&lt;/span&gt;.Lookup(webAppURI), appServer1, &lt;span style="color: #2b91af"&gt;SPJobLockType&lt;/span&gt;.Job);

&lt;span style="color: green"&gt;//Job associated with the timer service, a particular app server and none lock:
//  will run on the appServer1 server only.
&lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;jobRunningOnAppServer = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;MyTimerJob1&lt;/span&gt;(&lt;span style="color: #a31515"&gt;&amp;quot;mytimerjob&amp;quot;&lt;/span&gt;, 
    SPFarm.Local.TimerService, appServer1, &lt;span style="color: #2b91af"&gt;SPJobLockType&lt;/span&gt;.None);&lt;/pre&gt;


&lt;p&gt;&lt;u&gt;&lt;strong&gt;&lt;font size="4"&gt;Using Subclases&lt;/font&gt;&lt;/strong&gt;&lt;/u&gt;&lt;/p&gt;

&lt;p&gt;There are some other classes on the Sharepoint Object Model that inherit from the SPServiceJob definition and can be used to inherit our custom timer jobs from. For example:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;SPContentDatabaseJobDefinition&lt;/strong&gt;: This job is executed by all WFE servers in the farm. Each content database is processed by only one job so that work is distributed across all the running jobs.&lt;/li&gt;

  &lt;li&gt;&lt;strong&gt;SPFirstAvailableServiceJobDefinition&lt;/strong&gt;:

    &lt;br /&gt;An abstract base class for a timer job that will be run on the first available server where the specified service is provisioned.&lt;/li&gt;

  &lt;li&gt;&lt;strong&gt;SPServerJobDefinition&lt;/strong&gt;:This job definition is executed on a specific server within the SharePoint farm.&lt;/li&gt;

  &lt;li&gt;&lt;strong&gt;SPServiceJobDefinition&lt;/strong&gt;: A timer job that runs on every server in the farm where the service is provisioned.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So, for example, if you need a job to run on &lt;strong&gt;all&lt;/strong&gt; servers (including the app servers) it would be better to derive directly from the SPServiceJobDefinition class and, if you need a job to run in one particular app server, to derive from SPServerJobDefinition.&amp;#160; &lt;p&gt;&lt;font color="#000000"&gt;&amp;#160;&lt;/font&gt;&lt;/p&gt;&lt;/p&gt;</description><pubDate>Sun, 10 Jun 2012 02:51:27 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/spano/where-is-my-sharepoint-2010-custom-timer-job-running</guid><category>Sharepoint</category></item><item><title>Azure Flavor for the Sharepoint Media Component</title><link>https://weblogs.asp.net:443/spano/azure-flavor-for-the-sharepoint-media-component</link><description>&lt;p&gt;Some time ago I wrote about a &lt;a href="http://weblogs.asp.net/spano/archive/2012/01/12/media-processing-component-for-sharepoint.aspx"&gt;Media Processing Component for Sharepoint&lt;/a&gt; that I was working on. It is a Media Assets list for Sharepoint that lets you choose where to store the blob files. It provides also intelligence for encoding videos, generating thumbnail and poster images, obtaining media metadata, etc. On that &lt;a href="http://weblogs.asp.net/spano/archive/2012/01/12/media-processing-component-for-sharepoint.aspx"&gt;first post&lt;/a&gt; the component was explained in detail, with the original 3 storage flavors: Sharepoint list, Virtual Directoy or FTP. The storage manager is extensible, so &lt;a href="http://weblogs.asp.net/spano/archive/2012/01/22/media-from-sharepoint-to-the-cloud.aspx"&gt;a new flavor was added later&lt;/a&gt; that enabled to store the media files on the cloud, in particular to AmazonS3. Today I’m going to talk about a new cloud flavor based on Azure Blob Storage. &lt;/p&gt;  &lt;p&gt;Windows Azure Blob storage is a service for storing large amounts of unstructured data that can be accessed from anywhere in the world via HTTP or HTTPS. This kind of storage is special for storing large amounts of unstructured text or binary data such as video, audio and images. You can find documentation &lt;a href="https://www.windowsazure.com/en-us/develop/net/how-to-guides/blob-storage/"&gt;here&lt;/a&gt; on how to create a Windows Azure Storage Account and access it programmatically.&lt;/p&gt;  &lt;p&gt;For the Media Processing Component I just needed to create a class (AzureStorageManager) that implemented the IAssetStorageManager interface. The interface has the methods to save and delete files from the external storage. It also needs four configuration parameters to be passed to its constructor:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;AccountName: Name of the account that will be used to authenticate to the Blob Storage &lt;/li&gt;    &lt;li&gt;AccountKey: Key that will be used to authenticate to the Blob Storage &lt;/li&gt;    &lt;li&gt;BlobEndpoint: URL of the Blob endpoint, like &lt;a href="http://someaccount.blob.core.windows.net"&gt;http://someaccount.blob.core.windows.net&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;Container: Name of a container to store your application’s media files. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;For example, this is the code required to upload a file to an Azure Blob Storage:&lt;/p&gt;  &lt;div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: courier new, courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid"&gt;   &lt;div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px"&gt;Code Snippet AzureStorageManager class - Save method&lt;/div&gt; &lt;/div&gt;  &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt;   &lt;ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px"&gt;     &lt;li&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; Save(System.IO.&lt;span style="color: #2b91af"&gt;FileInfo&lt;/span&gt; file) &lt;/li&gt;      &lt;li style="background: #f3f3f3"&gt;{ &lt;/li&gt;      &lt;li&gt;&lt;span style="color: #008000"&gt;//Create service client for credentialed access to the Blob service.&lt;/span&gt; &lt;/li&gt;      &lt;li style="background: #f3f3f3"&gt;&lt;span style="color: #2b91af"&gt;CloudBlobClient&lt;/span&gt; blobClient = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;CloudBlobClient&lt;/span&gt;(blobEndpoint, &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;StorageCredentialsAccountAndKey&lt;/span&gt;(accountName, accountKey)); &lt;/li&gt;      &lt;li&gt;&lt;/li&gt;      &lt;li style="background: #f3f3f3"&gt;&lt;span style="color: #008000"&gt;//Get a reference to a container, which may or may not exist.&lt;/span&gt; &lt;/li&gt;      &lt;li&gt;&lt;span style="color: #2b91af"&gt;CloudBlobContainer&lt;/span&gt; container = blobClient.GetContainerReference(containerAddress); &lt;/li&gt;      &lt;li style="background: #f3f3f3"&gt;&lt;/li&gt;      &lt;li&gt;&lt;span style="color: #008000"&gt;//Create a new container, if it does not exist&lt;/span&gt; &lt;/li&gt;      &lt;li style="background: #f3f3f3"&gt;container.CreateIfNotExist(); &lt;/li&gt;      &lt;li&gt;&lt;/li&gt;      &lt;li style="background: #f3f3f3"&gt;&lt;span style="color: #008000"&gt;//Get a reference to a blob, which may or may not exist.&lt;/span&gt; &lt;/li&gt;      &lt;li&gt;&lt;span style="color: #2b91af"&gt;CloudBlob&lt;/span&gt; blob = container.GetBlobReference(file.Name); &lt;/li&gt;      &lt;li style="background: #f3f3f3"&gt;&lt;/li&gt;      &lt;li&gt;&lt;span style="color: #008000"&gt;//Upload content to the blob, which will create the blob if it does not already exist.&lt;/span&gt; &lt;/li&gt;      &lt;li style="background: #f3f3f3"&gt;blob.UploadFile(file.FullName); &lt;/li&gt;      &lt;li&gt;&lt;/li&gt;      &lt;li style="background: #f3f3f3"&gt;&lt;span style="color: #0000ff"&gt;return&lt;/span&gt; blob.Uri.ToString(); &lt;/li&gt;      &lt;li&gt;} &lt;/li&gt;   &lt;/ol&gt; &lt;/div&gt;  &lt;p&gt;You can download the complete code for the Media Component with all the storage options from &lt;a href="https://github.com/TellagoDevLabs/CloudPoint"&gt;gitgub&lt;/a&gt;. &lt;/p&gt;</description><pubDate>Sun, 27 May 2012 13:35:41 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/spano/azure-flavor-for-the-sharepoint-media-component</guid><category>Azure</category><category>Cloud</category><category>Sharepoint</category></item><item><title>Sharepoint Guidance Logger: usage, setup and extension</title><link>https://weblogs.asp.net:443/spano/sharepoint-guidance-logger-usage-setup-and-extension</link><description>&lt;h3&gt;Introduction&lt;/h3&gt;  &lt;p&gt;Log records are essential to any application for troubleshooting problems. When beginning a new Sharepoint project, one of the first needs is to have a core logging component that can be used throughout the application code. In this post I will talk about the logging solution that we are using (based on the Patterns &amp;amp; Practices &lt;a href="http://msdn.microsoft.com/en-us/library/ff798395.aspx"&gt;Sharepoint Logger&lt;/a&gt;), how to set it up, configure and read logs. &lt;/p&gt;  &lt;p&gt;SharePoint 2010 includes enhanced functionality for logging and tracing. You can now throttle reporting to the Windows Event Log and the Office Server Unified Logging Service (ULS) trace logs by &lt;i&gt;area&lt;/i&gt; and by &lt;i&gt;category&lt;/i&gt;. Areas represent broad regions of SharePoint functionality, such as Access Services, Business Connectivity Services, and Document Management Server. Within each area, categories define more specific aspects of functionality. In our solution we use a single Area for the whole project’s custom code, and different categories inside it for the different components, like Caching, UserProfile, News, Workflows, etc… &lt;/p&gt;  &lt;p&gt;In addition to areas and categories, SharePoint 2010 makes substantial improvements to event correlation. Every trace log entry now includes a correlation ID that identifies all the events that correspond to a particular action, such as a user uploading a document. Administrators can use tools such as the ULS Viewer to filter the trace logs by correlation ID. The Sharepoint Error Page shows the user the date and correlation Id. It is important to capture this information when an error occurs, to make it easier for administrators to track for a particular issue. &lt;/p&gt;  &lt;h3&gt;The Framework&lt;/h3&gt;  &lt;p&gt;In the project I’m working on we are using a common framework for logging, which is based on the Patterns &amp;amp; Practices &lt;a href="http://msdn.microsoft.com/en-us/library/ff798395.aspx"&gt;Sharepoint Logger&lt;/a&gt;, included in the &lt;a href="http://msdn.microsoft.com/en-us/library/ff770300.aspx"&gt;SharePoint Guidance Library&lt;/a&gt;. The P&amp;amp;P logger provides support to write to the Windows Event log and the ULS trace logs and support for creating your own areas and categories and use them when you write to the event log or the trace logs. Two external assemblies are needed for using it: Microsoft.Practices.ServiceLocation.dll and Microsoft.Practices.SharePoint.Common.dll. &lt;/p&gt;  &lt;p&gt;Examples of how to call the logger thru code can be found on the &lt;a href="http://msdn.microsoft.com/en-us/library/ff798306.aspx"&gt;SP logger documentation&lt;/a&gt;, but just as a sample, it is something like this:&lt;/p&gt;  &lt;pre&gt;&lt;div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid"&gt;&lt;div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px"&gt;P&amp;amp;P Logger usage&lt;/div&gt;&lt;div style="padding-bottom: 2px; background-color: #ffffff; padding-left: 5px; padding-right: 5px; max-height: 300px; overflow: auto; padding-top: 2px"&gt;&lt;span style="color: #008000"&gt;// Log an event with a message, an event ID, a severity level, and a category.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; area = &lt;span style="color: #a31515"&gt;&amp;quot;Custom Area&amp;quot;&lt;/span&gt;;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; category = &lt;span style="color: #a31515"&gt;&amp;quot;Execution&amp;quot;&lt;/span&gt;;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; areaCategory = &lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.Format(&lt;span style="color: #a31515"&gt;&amp;quot;{0}/{1}&amp;quot;&lt;/span&gt;, area, category);&lt;br /&gt;logger.LogToOperations(msg, (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;) EventLogEventId.MissingPartnerID, &lt;span style="color: #2b91af"&gt;EventSeverity&lt;/span&gt;.Error, areaCategory);&lt;/div&gt;&lt;/div&gt; &lt;/pre&gt;

&lt;p&gt;Our logging component adds a small utility layer above the P&amp;amp;P logger to simplify this lines a little more. For example, as we have our custom area and categories predefined, we included them in an enumeration, and use the enums as parameters to the LogToOperations method. This way developers don’t need to type the area and categories names every time, which can lead to a lot of errors. It also provides the option to add parameters to the message and then does the String.Format to combine the message with the parameters inside the utility class, this saves some repeated code to the developers as well. Regarding the log event ids, they are also set automatically by the utility class, using a different number for each category, starting with 5000. &lt;/p&gt;

&lt;p&gt;This leads to the logger utility having two overrides of the LogToOperations method, one for logging messages and the other for logging exceptions: &lt;/p&gt;

&lt;div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid"&gt;
  &lt;div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px"&gt;Custom logger utility&lt;/div&gt;

  &lt;div style="padding-bottom: 2px; background-color: #ffffff; padding-left: 5px; padding-right: 5px; max-height: 300px; overflow: auto; padding-top: 2px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af"&gt;Logger&lt;/span&gt; 

    &lt;br /&gt;{ 

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #2b91af"&gt;ILogger&lt;/span&gt; logger = &lt;span style="color: #2b91af"&gt;SharePointServiceLocator&lt;/span&gt;.GetCurrent().GetInstance&amp;lt;&lt;span style="color: #2b91af"&gt;ILogger&lt;/span&gt;&amp;gt;(); 

    &lt;br /&gt;

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; LogToOperations(&lt;span style="color: #2b91af"&gt;MyCustomCategories&lt;/span&gt; category, &lt;span style="color: #2b91af"&gt;EventSeverity&lt;/span&gt; severity, &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; message, &lt;span style="color: #0000ff"&gt;params&lt;/span&gt; &lt;span style="color: #0000ff"&gt;object&lt;/span&gt;[] args) 

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; { 

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;try&lt;/span&gt; 

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; { 

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; logger.LogToOperations(&lt;span style="color: #2b91af"&gt;String&lt;/span&gt;.Format(message, args), GetEventId(category), 

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; severity, category.ToLoggerString()); 

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } 

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;catch&lt;/span&gt; 

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; { 

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #008000"&gt;//don't want the app to fail because of failures in logging &lt;/span&gt;

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } 

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; } 

    &lt;br /&gt;

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; LogToOperations(&lt;span style="color: #2b91af"&gt;Exception&lt;/span&gt; ex, &lt;span style="color: #2b91af"&gt;MyCustomCategories&lt;/span&gt; category, &lt;span style="color: #2b91af"&gt;EventSeverity&lt;/span&gt; severity, &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; message, &lt;span style="color: #0000ff"&gt;params&lt;/span&gt; &lt;span style="color: #0000ff"&gt;object&lt;/span&gt;[] args) 

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; { 

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;try&lt;/span&gt; 

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; { 

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; logger.LogToOperations(ex, &lt;span style="color: #2b91af"&gt;String&lt;/span&gt;.Format(message, args), GetEventId(category), 

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; severity, category.ToLoggerString()); 

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } 

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;catch&lt;/span&gt; 

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; { 

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #008000"&gt;//don't want the app to fail because of failures in logging &lt;/span&gt;

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } 

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; } 

    &lt;br /&gt;

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; GetEventId(&lt;span style="color: #2b91af"&gt;MyCustomCategories&lt;/span&gt; category) 

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; { 

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; 5000 + (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;)category; 

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; } 

    &lt;br /&gt;}&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;&amp;#160; And this is a simple example of usage: &lt;/p&gt;

&lt;div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid"&gt;
  &lt;div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px"&gt;Usage example&lt;/div&gt;

  &lt;div style="padding-bottom: 2px; background-color: #ffffff; padding-left: 5px; padding-right: 5px; max-height: 300px; overflow: auto; padding-top: 2px"&gt;&lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Main(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;[] args) 

    &lt;br /&gt;{ 

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; user = &lt;span style="color: #a31515"&gt;&amp;quot;Peter John&amp;quot;&lt;/span&gt;; 

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; id = 3; 

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #2b91af"&gt;Logger&lt;/span&gt; logger = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;Logger&lt;/span&gt;(); 

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; logger.LogToOperations(&lt;span style="color: #2b91af"&gt;MyCustomCategories&lt;/span&gt;.Test, Microsoft.SharePoint.Administration.&lt;span style="color: #2b91af"&gt;EventSeverity&lt;/span&gt;.Verbose, 

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #a31515"&gt;&amp;quot;Testing logging with user '{0}' and id '{1}'&amp;quot;&lt;/span&gt;, user, id); 

    &lt;br /&gt;

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;try&lt;/span&gt; 

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; { 

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; firstArg = args[0]; 

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; } 

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;catch&lt;/span&gt; (&lt;span style="color: #2b91af"&gt;Exception&lt;/span&gt; ex) 

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; { 

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; logger.LogToOperations(ex,&lt;span style="color: #2b91af"&gt;MyCustomCategories&lt;/span&gt;.Test, Microsoft.SharePoint.Administration.&lt;span style="color: #2b91af"&gt;EventSeverity&lt;/span&gt;.Error, &lt;span style="color: #a31515"&gt;&amp;quot;Error ocurred in test program for user '{0}' and id '{1}'&amp;quot;&lt;/span&gt;, 

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; user, id); 

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; } 

    &lt;br /&gt;}&lt;/div&gt;
&lt;/div&gt;

&lt;h3&gt;Setup and Configuration&lt;/h3&gt;

&lt;p&gt;In order for all this to work, we first need to &lt;a href="http://msdn.microsoft.com/en-us/library/ff798462.aspx"&gt;create our custom diagnostic areas and categories&lt;/a&gt;. We are doing it inside a feature event receiver. The code adds the custom area and then iterates thru the Categories enum to add all the associated categories. The advantage is that when a developer needs to add a category, he just adds the value to the enum and the feature will automatically add it to Sharepoint. At the moment of crating the categories, the severity level must be set. We are setting all of them as verbose which is the most useful at a development stage, but this should be changed after deployment, especially in production. A level of Warning is recommended to save disk space and increase general performance of the application.&lt;/p&gt;

&lt;div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid"&gt;
  &lt;div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px"&gt;Installer helper called by the feature event receiver&lt;/div&gt;

  &lt;div style="padding-bottom: 2px; background-color: #ffffff; padding-left: 5px; padding-right: 5px; max-height: 300px; overflow: auto; padding-top: 2px"&gt;&lt;span style="color: #0000ff"&gt;class&lt;/span&gt; &lt;span style="color: #2b91af"&gt;LoggingInstallerHelper&lt;/span&gt;

    &lt;br /&gt;{

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; AddCustomAreaAndCategories()

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #2b91af"&gt;DiagnosticsArea&lt;/span&gt; customArea = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;DiagnosticsArea&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;Areas&lt;/span&gt;.MyCustomArea.ToString());

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;var&lt;/span&gt; categories = &lt;span style="color: #2b91af"&gt;Enum&lt;/span&gt;.GetNames(&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;MyCustomCategories&lt;/span&gt;));

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;foreach&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;var&lt;/span&gt; category &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; categories)

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; customArea.DiagnosticsCategories.Add(&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;DiagnosticsCategory&lt;/span&gt;(category, &lt;span style="color: #2b91af"&gt;EventSeverity&lt;/span&gt;.Verbose, &lt;span style="color: #2b91af"&gt;TraceSeverity&lt;/span&gt;.Verbose));

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; AddArea(customArea);

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }

    &lt;br /&gt;

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; RemoveCustomAreaAndCategories()

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; RemoveArea(&lt;span style="color: #2b91af"&gt;Areas&lt;/span&gt;.MyCustomArea.ToString());

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }

    &lt;br /&gt;

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;#region&lt;/span&gt; Private Methods

    &lt;br /&gt;

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; AddArea(&lt;span style="color: #2b91af"&gt;DiagnosticsArea&lt;/span&gt; newArea)

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #2b91af"&gt;DiagnosticsAreaCollection&lt;/span&gt; areas = GetCurrentAreas();

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;var&lt;/span&gt; existingArea = areas.FirstOrDefault(area =&amp;gt; area.Name == newArea.Name);

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (existingArea == &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; areas.Add(newArea);

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;else&lt;/span&gt;

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; index = areas.IndexOf(existingArea);

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;foreach&lt;/span&gt; (&lt;span style="color: #2b91af"&gt;DiagnosticsCategory&lt;/span&gt; item &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; newArea.DiagnosticsCategories)

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;var&lt;/span&gt; existingCateg = areas[index].DiagnosticsCategories.FirstOrDefault(categ =&amp;gt; categ.Name == item.Name);

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (existingCateg == &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; areas[index].DiagnosticsCategories.Add(item);

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; areas.SaveConfiguration();

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #2b91af"&gt;DiagnosticsAreaCollection&lt;/span&gt; GetCurrentAreas()

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #2b91af"&gt;IServiceLocator&lt;/span&gt; serviceLocator = &lt;span style="color: #2b91af"&gt;SharePointServiceLocator&lt;/span&gt;.GetCurrent();

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #2b91af"&gt;IConfigManager&lt;/span&gt; config = serviceLocator.GetInstance&amp;lt;&lt;span style="color: #2b91af"&gt;IConfigManager&lt;/span&gt;&amp;gt;();

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #2b91af"&gt;DiagnosticsAreaCollection&lt;/span&gt; areaCollection = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;DiagnosticsAreaCollection&lt;/span&gt;(config);

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; areaCollection;

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }

    &lt;br /&gt;

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; RemoveArea(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; areaName)

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #2b91af"&gt;DiagnosticsAreaCollection&lt;/span&gt; areas = GetCurrentAreas();

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (ExistArea(areas, areaName))

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;while&lt;/span&gt; (areas[areaName].DiagnosticsCategories.Count != 0)

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; areas[areaName].DiagnosticsCategories.Clear();

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; areas.RemoveAt(areas.IndexOf(areas[areaName]));

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; areas.SaveConfiguration();

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }

    &lt;br /&gt;

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; ExistArea(&lt;span style="color: #2b91af"&gt;DiagnosticsAreaCollection&lt;/span&gt; collection, &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; areaName)

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;foreach&lt;/span&gt; (&lt;span style="color: #2b91af"&gt;DiagnosticsArea&lt;/span&gt; item &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; collection)

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (item.Name.Trim().ToUpper() == areaName.Trim().ToUpper())

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;;

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;;

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }

    &lt;br /&gt;

    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: #0000ff"&gt;#endregion&lt;/span&gt;

    &lt;br /&gt;

    &lt;br /&gt;}&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;To verify the proper installation of the custom area and categories and modify their severity level, you can go to the Admin Site -&amp;gt; Monitoring -&amp;gt; (Reporting) Configure diagnostic logger. In the Event Throttling section select desired area or particular categories and change the event and trace levels. Then click ok.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://aspblogs.blob.core.windows.net/media/spano/Media/LoggingConfig_5957A88F.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="LoggingConfig" border="0" alt="LoggingConfig" src="https://aspblogs.blob.core.windows.net/media/spano/Media/LoggingConfig_thumb_3647371F.png" width="640" height="348" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can also configure the logs folder path (the default is c:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\LOGS\), storage day and size limits on this page under the trace logs section.&lt;/p&gt;

&lt;h3&gt;Viewing logs&lt;/h3&gt;

&lt;p&gt;You can see the log messages on the Event Viewer and trace logs using the ULS Viewer.&lt;/p&gt;

&lt;p&gt;In the Event Viewer you will find the custom events under Windows Logs/ Application. You can filter by Source = MyCustomArea, by severity and/or Event ID. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://aspblogs.blob.core.windows.net/media/spano/Media/EventLog_161C0495.jpg"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="EventLog" border="0" alt="EventLog" src="https://aspblogs.blob.core.windows.net/media/spano/Media/EventLog_thumb_2486DAED.jpg" width="640" height="428" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can also find trace logs in the ULS log files, and use a tool, like the &lt;a href="http://archive.msdn.microsoft.com/ULSViewer"&gt;ULS Viewer&lt;/a&gt; for a friendlier interface and filtering capabilities. The ULS Viewer is very useful for filtering by correlation id.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://aspblogs.blob.core.windows.net/media/spano/Media/ULS_3D728565.jpg"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="ULS" border="0" alt="ULS" src="https://aspblogs.blob.core.windows.net/media/spano/Media/ULS_thumb_11EE18D1.jpg" width="640" height="277" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This are the basic tools. There are also tools for viewing log information remotely, or for aggregating log entries in a farm environment.&lt;/p&gt;</description><pubDate>Tue, 20 Mar 2012 02:57:33 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/spano/sharepoint-guidance-logger-usage-setup-and-extension</guid><category>Sharepoint</category></item><item><title>Sharepoint Expiration Policy not working</title><link>https://weblogs.asp.net:443/spano/sharepoint-expiration-policy-not-working</link><description>&lt;p&gt;I have a Sharepoint 2010 list with a custom content type with an associated retention policy. The policy consists of a custom formula and then the Send to Recycle Bin action. However, I realized that the items were not being deleted. I verified the list settings and the retention policy was configured:&lt;/p&gt;  &lt;p&gt;&lt;a href="https://aspblogs.blob.core.windows.net/media/spano/Media/CustomExpirationFormula_56D5680D.jpg"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="CustomExpirationFormula" border="0" alt="CustomExpirationFormula" src="https://aspblogs.blob.core.windows.net/media/spano/Media/CustomExpirationFormula_thumb_5966979A.jpg" width="644" height="135" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;I run the &lt;strong&gt;Expiration Policy&lt;/strong&gt; job several times but no items were deleted and no errors found in the logs. I also added logging to the custom formula but no logging was found neither. Finally, I found one thing that I didn’t know: There is another job that needs to be run before the &lt;strong&gt;Expiration Policy&lt;/strong&gt; job, it is the &lt;strong&gt;Information Management Policy&lt;/strong&gt; job.&lt;/p&gt;  &lt;p&gt;The two are Sharepoint OOB jobs:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;Expiration Policy&lt;/strong&gt;: This job processes items that are due for a retention action, such as deleting items passed their expiration date.&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Information Management Policy&lt;/strong&gt;:&lt;strong&gt; &lt;/strong&gt;This job performs background processing for information policies, such as calculating updated expiration dates for items with a new retention policy.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;So as in this case I have a new retention policy, I needed to run this job first. When I did it, I got an error in the logs:&lt;/p&gt;  &lt;table border="1" cellspacing="0" cellpadding="2" width="445"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="443"&gt;         &lt;p&gt;Error processing policy updates for site &lt;a href="http://mysite.com"&gt;http://mysite.com&lt;/a&gt; for list MyList.&lt;/p&gt;          &lt;p&gt;Error: Object reference not set to an instance of an object.&lt;/p&gt;          &lt;p&gt;Source: Document Management Server&lt;/p&gt;          &lt;p&gt;Event ID: 7997&lt;/p&gt;          &lt;p&gt;Task Category: Information Policy Management&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;The error didn’t tell much, but after digging a little more I realized that the problem was that the custom expiration formula was not installed, so the Information Management Policy job couldn’t calculate the expiration date.&lt;/p&gt;</description><pubDate>Sat, 17 Mar 2012 20:36:09 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/spano/sharepoint-expiration-policy-not-working</guid><category>Sharepoint</category></item><item><title>Media from Sharepoint to the Cloud</title><link>https://weblogs.asp.net:443/spano/media-from-sharepoint-to-the-cloud</link><description>&lt;p&gt;On &lt;a href="http://weblogs.asp.net/spano/archive/2012/01/12/media-processing-component-for-sharepoint.aspx"&gt;my last post&lt;/a&gt; I talked about a media processing component developed for Sharepoint 2010. Besides the processing features (video encoding, thumbnail generation, validations, etc…) there was an asset storage manager that enabled us to store the files on a configurable place, inside or outside Sharepoint. I said we initially started with three storage flavors: a Sharepoint library, an FTP server or a shared folder/virtual directory.&lt;/p&gt;  &lt;p&gt;My co-worker &lt;a href="http://dgoins.wordpress.com/2012/01/19/using-amazon-s3-as-a-media-hosting-option-for-sharepoint-2010/"&gt;Dwight Goins&lt;/a&gt; has extended the options by adding a cloud based storage manager. In this case he uses the &lt;a href="http://aws.amazon.com/s3/"&gt;Amazon Simple Storage Service (Amazon S3)&lt;/a&gt;, which resulted in a great performing storage solution. In &lt;a href="http://dgoins.wordpress.com/2012/01/19/using-amazon-s3-as-a-media-hosting-option-for-sharepoint-2010/"&gt;his post&lt;/a&gt;, he digs deeper in the issues of storing BLOBs (Binary Large Objects) in Sharepoint and the solution that Sharepoint provides, SQL’s &lt;a href="http://technet.microsoft.com/en-us/library/ff628583.aspx"&gt;Remote BLOB Storage&lt;/a&gt; (RBS). Then he talks about our solution and the details of the AmazonS3 client. &lt;a href="http://dgoins.wordpress.com/2012/01/19/using-amazon-s3-as-a-media-hosting-option-for-sharepoint-2010/"&gt;Check this out&lt;/a&gt;! &lt;/p&gt;</description><pubDate>Sun, 22 Jan 2012 23:32:00 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/spano/media-from-sharepoint-to-the-cloud</guid><category>Cloud</category><category>Sharepoint</category></item><item><title>Media Processing Component for Sharepoint</title><link>https://weblogs.asp.net:443/spano/media-processing-component-for-sharepoint</link><description>&lt;p&gt;I have been working recently on the task of building a media processing component for the Sharepoint project I am working on. The requirements for the component are more or less the following:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;The Site Content Creators must be able to upload media assets (images, audio and video) to a Sharepoint list, and these assets must accomplish certain validation rules. &lt;/li&gt;    &lt;li&gt;The final destination where the assets are saved after upload must be configurable and extensible. To begin with, we are supporting saving to a Sharepoint library, a network share or an FTP server. &lt;/li&gt;    &lt;li&gt;The videos must be encoded to MP4 format, and thumbnail and poster images must be generated. The encoding process must be run asynchronously and the user must be notified by email when it is finished. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Today I want to share the design of the component and the key pieces of code. I will focus on the video upload process which is the more complex one because of the encoding. Audio and image uploads are more straightforward.&lt;/p&gt;  &lt;p&gt;The main parts that build the solution are: &lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;strong&gt;Custom Upload Process&lt;/strong&gt;: This is the front end of the solution. It consists of a custom list with a custom upload form. The list has the link to the media file and more metadata fields (title, author, date, keywords, etc). When you click on create a new item on the list the custom upload form is opened and you can browse for a file to upload. The form has the required validation logic and it serves to save the assets to the configured location, which can be a Sharepoint library or an external location, like File System or FTP server. When the upload finishes you are redirected to the list item edit form so you can enter the metadata. The experience is similar to uploading a file to a Sharepoint document library. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Media Processing Backend Process&lt;/strong&gt;: This consists of a timer job that queries the Media Assets list for items to process. It encodes the videos, generates thumbnail and poster images and uploads everything to the final destination. Finally, it notifies the user of the result of the process by email. For the video encoding we used the Microsoft Expression Encoder SDK. As I will explain later, this SDK cannot be used inside a Sharepoint process, so it runs in a separated process that is invoked from the timer job. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Storage Manager&lt;/strong&gt;: this is a flexible and extensible component that abstracts the logic of saving (and deleting) a file to the final location depending on the flavor chosen thru configuration (File System, Sharepoint library or FTP). This component is used both by the front end upload mechanism and the back end media processing job. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Here is a diagram of the overall design for the video processing:&lt;/p&gt;  &lt;p&gt;&lt;a href="https://aspblogs.blob.core.windows.net/media/spano/Media/MediaProcessing_0AFECC3C.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="MediaProcessing" border="0" alt="MediaProcessing" src="https://aspblogs.blob.core.windows.net/media/spano/Media/MediaProcessing_thumb_47BF1442.png" width="519" height="480" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Now I will explain in a little more detail each component:&lt;/p&gt;  &lt;h4&gt;&lt;u&gt;1. Custom Upload Process&lt;/u&gt;&lt;/h4&gt;  &lt;h5&gt;The Media Assets List&lt;/h5&gt;  &lt;p&gt;This is a Sharepoint list that stores the metadata of the media assets, but not the asset itself (the assets are stored in the definite storage, which can be a Sharepoint assets library, a network shared folder, or an FTP server). The list is based on three custom content types, WebVideo, WebAudio and WebImage, all three inheriting from a base MediaAsset content type. This content type has the required fields for saving the asset metadata. The more important ones for the processing being: &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;Location&lt;/strong&gt;: the URL of the asset in its definite location (in the example on the picture it is a sharepoint library called MediaAssetsLib). &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Temp Location&lt;/strong&gt;: As videos needs asynchronous processing, they are saved in a temporary location on upload. It is the timer job that uploads them to the definite location after encoding. The temp location is a shared folder on the network. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Processing Status&lt;/strong&gt;: It is &lt;em&gt;Success&lt;/em&gt; for assets successfully uploaded to the definite storage, &lt;em&gt;Pending&lt;/em&gt; for assets waiting for encoding in the back end process and &lt;em&gt;Error&lt;/em&gt; in case of encoding fail. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;a href="https://aspblogs.blob.core.windows.net/media/spano/Media/MediaAssetsList_6E86FAC2.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="MediaAssetsList" border="0" alt="MediaAssetsList" src="https://aspblogs.blob.core.windows.net/media/spano/Media/MediaAssetsList_thumb_52EDBEF3.png" width="644" height="177" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The list has an event receiver attached in order for deleting the assets from the final destination or temporary folder when the items are deleted from the list.&lt;/p&gt;  &lt;p&gt;To achieve the storage flexibility, a custom upload form was developed and hooked to the MediaAssets list. When you click on the “Add new item” link of the picture above, the custom upload form is launched. The form is attached to the base content type definition in the Elements file as this:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;?&lt;/span&gt;&lt;span style="color: #a31515"&gt;xml &lt;/span&gt;&lt;span style="color: red"&gt;version&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;1.0&lt;/span&gt;&amp;quot; &lt;span style="color: red"&gt;encoding&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;utf-8&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;?&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Elements &lt;/span&gt;&lt;span style="color: red"&gt;xmlns&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;http://schemas.microsoft.com/sharepoint/&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;&amp;gt;
  &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;!-- &lt;/span&gt;&lt;span style="color: green"&gt;Parent ContentType: Item (0x01) &lt;/span&gt;&lt;span style="color: blue"&gt;--&amp;gt;
  &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;ContentType &lt;/span&gt;&lt;span style="color: red"&gt;ID&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;0x01004e4f21afc14c487892253cb129dd5001&lt;/span&gt;&amp;quot;
               &lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;MyMediaAsset&lt;/span&gt;&amp;quot; &lt;span style="color: red"&gt;Group&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;MyContent Types&lt;/span&gt;&amp;quot;
               &lt;span style="color: red"&gt;Description&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;My Media Asset&lt;/span&gt;&amp;quot; &lt;span style="color: red"&gt;Inherits&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;TRUE&lt;/span&gt;&amp;quot;
               &lt;span style="color: red"&gt;Version&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;0&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;FieldRefs&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;span style="color: blue"&gt;    …&lt;/span&gt;&lt;span style="color: blue"&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;FieldRefs&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;XmlDocuments&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
      &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;XmlDocument &lt;/span&gt;&lt;span style="color: red"&gt;NamespaceURI&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;http://schemas.microsoft.com/sharepoint/v3/contenttype/forms/url&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;FormUrls &lt;/span&gt;&lt;span style="color: red"&gt;xmlns&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;http://schemas.microsoft.com/sharepoint/v3/contenttype/forms/url&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;&amp;gt;
          &lt;font style="background-color: #ffff00"&gt;&amp;lt;&lt;/font&gt;&lt;/span&gt;&lt;font style="background-color: #ffff00"&gt;&lt;span style="color: #a31515"&gt;New&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;_layouts/MyMedia/Upload.aspx&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;New&lt;/span&gt;&lt;/font&gt;&lt;span style="color: blue"&gt;&lt;font style="background-color: #ffff00"&gt;&amp;gt;&lt;/font&gt;
        &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;FormUrls&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
      &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;XmlDocument&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;XmlDocuments&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
  &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;ContentType&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Elements&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;

&lt;/span&gt;&lt;/pre&gt;

&lt;h5&gt;The Upload Form&lt;/h5&gt;

&lt;p&gt;The form was created as an Application Page (Upload.aspx) in the Layouts folder. It contains the browse control to upload the file.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://aspblogs.blob.core.windows.net/media/spano/Media/MediaAssetUploadForm_64D7103B.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="MediaAssetUploadForm" border="0" alt="MediaAssetUploadForm" src="https://aspblogs.blob.core.windows.net/media/spano/Media/MediaAssetUploadForm_thumb_074B9EF7.png" width="556" height="449" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A useful tip here is how to achieve the same look and feel as the Sharepoint OOB forms. The InputFormSeccion, InputFormControl and ButtonSection controls were used for that matter. &lt;/p&gt;

&lt;p&gt;In order to use these controls, you need to register the namespace on the top of the page:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="background: yellow"&gt;&amp;lt;%&lt;/span&gt;&lt;span style="color: blue"&gt;@ &lt;/span&gt;&lt;span style="color: maroon"&gt;Register &lt;/span&gt;&lt;span style="color: red"&gt;TagPrefix&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;wssuc&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;TagName&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;ButtonSection&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Src&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;/_controltemplates/ButtonSection.ascx&amp;quot; &lt;/span&gt;&lt;span style="background: yellow"&gt;%&amp;gt;
&amp;lt;%&lt;/span&gt;&lt;span style="color: blue"&gt;@ &lt;/span&gt;&lt;span style="color: maroon"&gt;Register &lt;/span&gt;&lt;span style="color: red"&gt;TagPrefix&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;wssuc&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;TagName&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;InputFormSection&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Src&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;/_controltemplates/InputFormSection.ascx&amp;quot; &lt;/span&gt;&lt;span style="background: yellow"&gt;%&amp;gt;
&amp;lt;%&lt;/span&gt;&lt;span style="color: blue"&gt;@ &lt;/span&gt;&lt;span style="color: maroon"&gt;Register &lt;/span&gt;&lt;span style="color: red"&gt;TagPrefix&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;wssuc&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;TagName&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;InputFormControl&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Src&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;/_controltemplates/InputFormControl.ascx&amp;quot; &lt;/span&gt;&lt;span style="background: yellow"&gt;%&amp;gt;

&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;And then include them in the page like this:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;wssuc&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: maroon"&gt;&lt;strong&gt;&lt;font style="background-color: #ffff00"&gt;InputFormSection&lt;/font&gt;&lt;/strong&gt; &lt;/span&gt;&lt;span style="color: red"&gt;ID&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;InputFormSection1&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;runat&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;server&amp;quot;
      &lt;/span&gt;&lt;span style="color: red"&gt;Title&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Upload Document&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Description&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Browse to the media asset you intend to upload.&amp;quot; &amp;gt;
  &amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;template_inputformcontrols&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;wssuc&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: maroon"&gt;&lt;strong&gt;&lt;font style="background-color: #ffff00"&gt;InputFormControl&lt;/font&gt;&lt;/strong&gt; &lt;/span&gt;&lt;span style="color: red"&gt;runat&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;server&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;LabelText&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;&amp;quot; &amp;gt;
      &amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;Template_Control&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;                   
        &amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;div &lt;/span&gt;&lt;span style="color: red"&gt;class&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;ms-authoringcontrols&amp;quot;&amp;gt;
          &lt;/span&gt;Name: &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;br &lt;/span&gt;&lt;span style="color: blue"&gt;/&amp;gt;
          &amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;input &lt;/span&gt;&lt;span style="color: red"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;FileToUpload&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;class&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;ms-fileinput&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;size&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;35&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;type&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;file&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;runat&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;server&amp;quot;&amp;gt;    
          &amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;asp&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: maroon"&gt;RequiredFieldValidator &lt;/span&gt;&lt;span style="color: red"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;RequiredFieldValidator&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;runat&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;server&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;ErrorMessage&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;You must specify a value for the required field.&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;ControlToValidate&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;FileToUpload&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;asp&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: maroon"&gt;RequiredFieldValidator&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
          &amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;br &lt;/span&gt;&lt;span style="color: blue"&gt;/&amp;gt;
          &amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;asp&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: maroon"&gt;RegularExpressionValidator &lt;/span&gt;&lt;span style="color: red"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;FileExtensionValidator&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;runat&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;server&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;ErrorMessage&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Invalid file name.&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;ControlToValidate&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;FileToUpload&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;asp&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: maroon"&gt;RegularExpressionValidator&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
          &lt;/span&gt;&lt;span style="color: blue"&gt;…&lt;/span&gt;&lt;span style="color: blue"&gt;                                                                          
        &amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;div&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
      &amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;Template_Control&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;wssuc&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: maroon"&gt;InputFormControl&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
  &amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;template_inputformcontrols&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;wssuc&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: maroon"&gt;InputFormSection&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;You can read more about how to use these controls &lt;a href="http://karinebosch.wordpress.com/sharepoint-controls/inputformsectionascx-control/"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;So, what happens in the code behind? &lt;/p&gt;

&lt;p&gt;On the OK button submit handler, the file to upload is processed. The logic is different depending on the asset type. Images are copied to the final destination by using the Storage Manager. A thumbnail is also generated and uploaded for them. Duration is calculated for Audio and Video files (Microsoft.WindowsAPICodePack API is used for that). Audio files are also copied to the final destination. Videos instead are leaved in a temporary storage (a network shared folder), because they need to be processed later by the timer job.&lt;/p&gt;

&lt;p&gt;In all three cases, a list item is created with the asset metadata, and inserted into the MediaAssets list. Then the user is redirected to the list item Edit form, so he can complete filling the rest of the metadata. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://aspblogs.blob.core.windows.net/media/spano/Media/MediaAssetsEditForm_21AB920E.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="MediaAssetsEditForm" border="0" alt="MediaAssetsEditForm" src="https://aspblogs.blob.core.windows.net/media/spano/Media/MediaAssetsEditForm_thumb_3FA9A002.png" width="623" height="402" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Since the upload process may take a long time, all this happens in the context of an SPLongOperation. This is a Sharepoint class provided to display the “Processing…” dialog with the rotating gear image in it.&lt;/p&gt;

&lt;p&gt;So, here is part of the code:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;protected void &lt;/span&gt;btnOk_Click(&lt;span style="color: blue"&gt;object &lt;/span&gt;sender, &lt;span style="color: #2b91af"&gt;EventArgs &lt;/span&gt;e)
{
    &lt;span style="color: blue"&gt;if &lt;/span&gt;(FileToUpload.PostedFile == &lt;span style="color: blue"&gt;null &lt;/span&gt;|| &lt;span style="color: #2b91af"&gt;String&lt;/span&gt;.IsNullOrEmpty(FileToUpload.PostedFile.FileName))
        &lt;span style="color: blue"&gt;return&lt;/span&gt;;     &lt;span style="color: green"&gt;//FileToUpload is the HtmlInputFile control
    &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;originFileInfo = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;FileInfo&lt;/span&gt;(FileToUpload.PostedFile.FileName);
    &lt;span style="color: #2b91af"&gt;SPWeb &lt;/span&gt;web = &lt;span style="color: #2b91af"&gt;SPContext&lt;/span&gt;.Current.Web;
    &lt;span style="color: blue"&gt;try
    &lt;/span&gt;{
        &lt;span style="color: green"&gt;//create a MediaAsset object to save all asset metadata
        &lt;/span&gt;&lt;span style="color: #2b91af"&gt;MediaAsset &lt;/span&gt;asset = &lt;span style="color: #2b91af"&gt;MediaAsset&lt;/span&gt;.FromFile(originFileInfo, web.Url, mediaConfig);
        &lt;span style="color: green"&gt;//start long operation to show the user the &amp;quot;Processing...&amp;quot; message
        &lt;/span&gt;&lt;span style="color: blue"&gt;using &lt;/span&gt;(&lt;span style="color: #2b91af"&gt;SPLongOperation &lt;/span&gt;longOperation = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;SPLongOperation&lt;/span&gt;(&lt;span style="color: blue"&gt;this&lt;/span&gt;.Page))
        {
            longOperation.Begin();

            &lt;span style="color: blue"&gt;string &lt;/span&gt;newFileUniqueName = &lt;span style="color: #2b91af"&gt;String&lt;/span&gt;.Concat(&lt;span style="color: #2b91af"&gt;Guid&lt;/span&gt;.NewGuid().ToString(), originFileInfo.Extension);

            &lt;span style="color: #2b91af"&gt;SPSecurity&lt;/span&gt;.RunWithElevatedPrivileges(&lt;span style="color: blue"&gt;delegate&lt;/span&gt;()
            {
                &lt;span style="color: green"&gt;//save to file system. Need to elevate privileges for that
                &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;tempFileInfo = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;FileInfo&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;Path&lt;/span&gt;.Combine(mediaConfig.TempLocationFolder, newFileUniqueName));
                FileToUpload.PostedFile.SaveAs(tempFileInfo.FullName);

                asset.TempLocation = tempFileInfo.FullName;
                asset.Duration = &lt;span style="color: #2b91af"&gt;MediaLengthCalculator&lt;/span&gt;.GetMediaLength(tempFileInfo);
                ...
            });
            
            &lt;span style="color: blue"&gt;var &lt;/span&gt;list = web.Lists[mediaConfig.MediaAssetsListName];
            &lt;span style="color: blue"&gt;int &lt;/span&gt;id;
            &lt;span style="color: blue"&gt;string &lt;/span&gt;contentTypeId;
            &lt;span style="color: green"&gt;//insert new item in the MediaAssets list
            &lt;/span&gt;mediaRepository.Insert(list, asset, &lt;span style="color: blue"&gt;out &lt;/span&gt;id, &lt;span style="color: blue"&gt;out &lt;/span&gt;contentTypeId);
            &lt;span style="color: green"&gt;//build url of Edit Form to redirect 
            &lt;/span&gt;&lt;span style="color: blue"&gt;string &lt;/span&gt;url = &lt;span style="color: #2b91af"&gt;String&lt;/span&gt;.Format(&lt;span style="color: #a31515"&gt;&amp;quot;{0}?ID={1}&amp;amp;ContentTypeId={2}&amp;quot;&lt;/span&gt;, list.DefaultEditFormUrl, id, contentTypeId);
            &lt;span style="color: green"&gt;//long operation ends, redirecting to the Edit Form of the new list item
            &lt;/span&gt;longOperation.End(url);
        }
    }
    &lt;span style="color: blue"&gt;catch &lt;/span&gt;(&lt;span style="color: #2b91af"&gt;ThreadAbortException&lt;/span&gt;) { &lt;span style="color: green"&gt;/* Thrown when redirected */&lt;/span&gt;}
    &lt;span style="color: blue"&gt;catch &lt;/span&gt;(&lt;span style="color: #2b91af"&gt;Exception &lt;/span&gt;ex)
    {
        logger.LogToOperations(ex, &lt;span style="color: #2b91af"&gt;Categories&lt;/span&gt;.Media, &lt;span style="color: #2b91af"&gt;EventSeverity&lt;/span&gt;.Error,
            &lt;span style="color: #a31515"&gt;&amp;quot;Error uploading file to MediaAssets list. FileName: '{0}'.&amp;quot;&lt;/span&gt;, originFileInfo.Name);

        &lt;span style="color: #2b91af"&gt;SPUtility&lt;/span&gt;.TransferToErrorPage(ex.Message);
    }
}&lt;/pre&gt;

&lt;p&gt;Ok, now let’s see how the asynchronous processing part works.&lt;/p&gt;

&lt;h4&gt;&lt;u&gt;2. Media Processing Backend Process&lt;/u&gt;&lt;/h4&gt;

&lt;p&gt;The backend process consists of a Sharepoint Timer Job that orchestrates the video processing and a console application that performs the actual encoding and generate the images. The console application is invoked by the timer job.&lt;/p&gt;

&lt;h5&gt;Encoder Console Application&lt;/h5&gt;

&lt;p&gt;The tool chosen for encoding videos was &lt;a href="http://social.expression.microsoft.com/Forums/en/encoder/thread/3eabf903-b49f-4f92-b508-f28a795d6c90"&gt;Microsoft Expression Encoder 4&lt;/a&gt;. We used the Pro version (paid) which includes support for H.264 (this means can encode videos to mp4 format as required by our client). &lt;/p&gt;

&lt;p&gt;The encoder comes with an SDK, so you can programmatically encode your videos. The thing is that this API depends upon .Net Framework 4.0, and it is also 32-bit only. This is incompatible with a Sharepoint process (either web or timer job), since Sharepoint relies upon .Net 3.5 and runs in 64 bits. Hence the need to build a separate process outside of the Sharepoint Timer Job. The console application was a simple solution, and it could be configured to target .Net Framework 4.0 and x86 Platform.&lt;/p&gt;

&lt;p&gt;This application expects four input parameters: the path to the original video, the desired path for the thumbnail image to generate, the desired path of the poster image to generate and the desired path of the encoded video to generate.&lt;/p&gt;

&lt;p&gt;The Encoder SDK provides full flexibility for setting the encoding parameters (like format, size, bitrate, etc). It also provides a set of presets, that let’s you implement the encoding very easily. For example, here is the code for encoding using the H264VimeoSD Preset:&lt;/p&gt;



&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public void &lt;/span&gt;EncodeVideo(&lt;span style="color: #2b91af"&gt;FileInfo &lt;/span&gt;inputFile, &lt;span style="color: #2b91af"&gt;FileInfo &lt;/span&gt;outputFile)
{
    Microsoft.Expression.Encoder.&lt;span style="color: #2b91af"&gt;MediaItem &lt;/span&gt;mediaItem = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;MediaItem&lt;/span&gt;(inputFile.FullName);
    &lt;span style="color: blue"&gt;int &lt;/span&gt;bitrate = GetBitrate(mediaItem);

    &lt;span style="color: blue"&gt;using &lt;/span&gt;(Microsoft.Expression.Encoder.&lt;span style="color: #2b91af"&gt;Job &lt;/span&gt;job = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Job&lt;/span&gt;())
    {
        job.OutputDirectory = outputFile.Directory.FullName;
        job.CreateSubfolder = &lt;span style="color: blue"&gt;false&lt;/span&gt;;
        job.MediaItems.Add(mediaItem);
        &lt;span style="color: green"&gt;//H264VimeoSD preset settings: Output Format: MP4. Container: MP4. Video Codec: H.264 - Main. 
        //Video size: 640, 480. Video Bitrate: 2500 Kbps. Video Encoding: CBR SinglePass. 
        //Audio Codec: AAC. Audio Channels: Stereo. Audio Bitrate: 128 Kbps. Audio Encoding: CBR Single Pass
        &lt;/span&gt;job.ApplyPreset(Microsoft.Expression.Encoder.&lt;span style="color: #2b91af"&gt;Presets&lt;/span&gt;.H264VimeoSD);
        job.Encode();
    }
}&lt;/pre&gt;


&lt;br /&gt;And here is the code for generating the thumbnail or poster images:



&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public void &lt;/span&gt;GenerateVideoImage(&lt;span style="color: #2b91af"&gt;FileInfo &lt;/span&gt;mediaFile, &lt;span style="color: blue"&gt;string &lt;/span&gt;imageFilePath, &lt;span style="color: blue"&gt;int &lt;/span&gt;width, &lt;span style="color: blue"&gt;int &lt;/span&gt;height)
{
    &lt;span style="color: blue"&gt;var &lt;/span&gt;video = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;MediaItem&lt;/span&gt;(mediaFile.FullName);
    &lt;span style="color: blue"&gt;using &lt;/span&gt;(&lt;span style="color: blue"&gt;var &lt;/span&gt;bitmap = video.MainMediaFile.GetThumbnail(
        &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;TimeSpan&lt;/span&gt;(0, 0, 5),
        &lt;span style="color: blue"&gt;new &lt;/span&gt;System.Drawing.&lt;span style="color: #2b91af"&gt;Size&lt;/span&gt;(width, height)))
    {
        bitmap.Save(imageFilePath, &lt;span style="color: #2b91af"&gt;ImageFormat&lt;/span&gt;.Jpeg);
    }
}&lt;/pre&gt;

&lt;h5&gt;Media Processing Timer Job&lt;/h5&gt;

&lt;p&gt;Sharepoint supports asynchronous processing of data through Timer Jobs. These jobs run within the context of a windows service, and are easily managed and deployed using the same tools as any other Sharepoint solution.&lt;/p&gt;

&lt;p&gt;As the requirement was to run the job only in one of the application servers, it inherits from &lt;a href="http://msdn.microsoft.com/en-us/library/ee543400.aspx"&gt;SPServerJobDefinition&lt;/a&gt;. Here is the Timer Job code:&lt;/p&gt;

&lt;p&gt;&lt;span style="color: blue"&gt;public class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;MediaProcessingTimerJob&lt;/span&gt;: &lt;span style="color: #2b91af"&gt;SPServerJobDefinition 
    &lt;br /&gt;&lt;/span&gt;{ 

  &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;private&lt;/span&gt;&lt;span style="color: #2b91af"&gt;Logger&lt;/span&gt;logger = &lt;span style="color: blue"&gt;new&lt;/span&gt;&lt;span style="color: #2b91af"&gt;Logger&lt;/span&gt;(); 

  &lt;br /&gt;

  &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;public&lt;/span&gt;MediaProcessingTimerJob() : &lt;span style="color: blue"&gt;base&lt;/span&gt;() 

  &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; { 

  &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; } 

  &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;public&lt;/span&gt;MediaProcessingTimerJob(&lt;span style="color: blue"&gt;string&lt;/span&gt;name,&lt;span style="color: #2b91af"&gt;SPServer &lt;/span&gt;server):&lt;span style="color: blue"&gt;base&lt;/span&gt;(name,server) 

  &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; { 

  &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;this&lt;/span&gt;.Title = &lt;span style="color: #a31515"&gt;&amp;quot;MediaProcessingTimerJob&amp;quot;&lt;/span&gt;; 

  &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; } 

  &lt;br /&gt;

  &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;public override void&lt;/span&gt;Execute(&lt;span style="color: #2b91af"&gt;SPJobState &lt;/span&gt;jobState) 

  &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; { 

  &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;string&lt;/span&gt;webUrl = &lt;span style="color: #2b91af"&gt;String&lt;/span&gt;.Empty; 

  &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;try 
    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;{ 

  &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; webUrl = &lt;span style="color: blue"&gt;this&lt;/span&gt;.Properties[&lt;span style="color: #a31515"&gt;&amp;quot;webUrl&amp;quot;&lt;/span&gt;].ToString(); 

  &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;var &lt;/span&gt;mediaProcessor = &lt;span style="color: blue"&gt;new&lt;/span&gt;&lt;span style="color: #2b91af"&gt;MediaProcessor&lt;/span&gt;(webUrl, &lt;span style="color: #2b91af"&gt;MediaConfig&lt;/span&gt;.FromConfigRepository(webUrl)); 

  &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; mediaProcessor.ProcessMedia(); 

  &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } 

  &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;catch&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;Exception&lt;/span&gt;ex) 

  &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; { 

  &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; logger.LogToOperations(ex,&lt;span style="color: #2b91af"&gt;Categories&lt;/span&gt;.Media, &lt;span style="color: #2b91af"&gt;EventSeverity&lt;/span&gt;.Error, &lt;span style="color: #a31515"&gt;&amp;quot;Error executing MediaProcessingTimerJob in web '{0}'&amp;quot;&lt;/span&gt;, webUrl); 

  &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } 

  &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; } 

  &lt;br /&gt;} 

  &lt;br /&gt;&lt;/p&gt;

&lt;p&gt;During the deployment process, the MediaProcessingTimerJob is installed on the required server. The URL of the website for processing the assets are passed thru the job properties. &lt;/p&gt;

&lt;p&gt;Here is part of the code of the helper tool that installs the job and sets it to run every 15 minutes:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;private static void &lt;/span&gt;CreateMediaJob(&lt;span style="color: blue"&gt;string &lt;/span&gt;webUrl,&lt;span style="color: #2b91af"&gt;SPServer &lt;/span&gt;server)
{
    &lt;span style="color: blue"&gt;var &lt;/span&gt;job = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;MediaProcessingTimerJob&lt;/span&gt;(&lt;span style="color: #a31515"&gt;&amp;quot;my-job-media-processing&amp;quot;&lt;/span&gt;, server);
            
    job.Properties.Add(&lt;span style="color: #a31515"&gt;&amp;quot;webUrl&amp;quot;&lt;/span&gt;, webUrl);
            
    &lt;span style="color: blue"&gt;var &lt;/span&gt;schedule = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;SPMinuteSchedule&lt;/span&gt;();
    schedule.BeginSecond = 0;
    schedule.EndSecond = 59;
    schedule.Interval = 15;
    job.Schedule = schedule;
    job.Update();
}&lt;/pre&gt;

&lt;p&gt;The logic of the timer job resides in the MediaProcessor::ProcessMedia method. It essentially queries the Media Assets List for assets in the “Pending” status and for each of these items it invokes the Encoder process and then uploads the resulting mp4 video and the generated thumbnail and poster images to the final destination. Finally it notifies the user of the result by email.&lt;/p&gt;

&lt;p&gt;&lt;font size="2"&gt;This is the code that the job uses to call the console application. Since the job tells the console application the output parameters (the path to the images and encoded video files), it doesn’t need to read any output from the console application. It must only read the standard error in case the console application fails.&lt;/font&gt;&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;private void &lt;/span&gt;ExecuteMediaProcess(&lt;span style="color: blue"&gt;string &lt;/span&gt;inVideoPath,&lt;span style="color: blue"&gt;string &lt;/span&gt;outThumbnailPath, &lt;span style="color: blue"&gt;string &lt;/span&gt;outPosterPath,&lt;span style="color: blue"&gt;string &lt;/span&gt;outVideoPath)
{
    &lt;span style="color: blue"&gt;string &lt;/span&gt;args = &lt;span style="color: #2b91af"&gt;String&lt;/span&gt;.Format(&lt;span style="color: #a31515"&gt;&amp;quot;\&amp;quot;{0}\&amp;quot; \&amp;quot;{1}\&amp;quot; \&amp;quot;{2}\&amp;quot; \&amp;quot;{3}\&amp;quot;&amp;quot;&lt;/span&gt;, inVideoPath, outThumbnailPath, outPosterPath, outVideoPath);

    &lt;span style="color: #2b91af"&gt;ProcessStartInfo &lt;/span&gt;startInfo = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;ProcessStartInfo&lt;/span&gt;(config.EncoderExePath);
    startInfo.Arguments = args;
    startInfo.CreateNoWindow = &lt;span style="color: blue"&gt;true&lt;/span&gt;;
    startInfo.UseShellExecute = &lt;span style="color: blue"&gt;false&lt;/span&gt;;
    startInfo.RedirectStandardError = &lt;span style="color: blue"&gt;true&lt;/span&gt;;
    startInfo.RedirectStandardOutput = &lt;span style="color: blue"&gt;true&lt;/span&gt;;

    &lt;span style="color: #2b91af"&gt;Process &lt;/span&gt;process = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Process&lt;/span&gt;();
    process.StartInfo = startInfo;
    process.Start();
    &lt;span style="color: blue"&gt;string &lt;/span&gt;error = process.StandardError.ReadToEnd();
    process.WaitForExit(MaxWaitingProcessMillisecs);

    &lt;span style="color: blue"&gt;if &lt;/span&gt;(process.ExitCode != 0)
    {
        &lt;span style="color: green"&gt;//the application failed, get error from message from standard error
        &lt;/span&gt;&lt;span style="color: blue"&gt;throw new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;MediaProcessingException&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;String&lt;/span&gt;.Format(&lt;span style="color: #a31515"&gt;&amp;quot;Video encoder process returned with exit code '{0}'. Error was: '{1}'&amp;quot;&lt;/span&gt;,
            process.ExitCode, error));
    }
}&lt;/pre&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;h4&gt;&lt;u&gt;3. Storage Manager&lt;/u&gt;&lt;/h4&gt;

&lt;p&gt;The Storage Manager is the piece of code used by both the upload media form and the backend process. It is just a file manager used for abstracting from the actual destination of the files, which is configurable. As I said, we started supporting saving assets to File System, to a Sharepoint library or to an FTP server, but this can be further extended to support other places, like some storage on the Cloud. &lt;/p&gt;

&lt;p&gt;The need for a flexibility in the location to store the files may come from bandwidth or space limitations, for a need to share assets with other applications or a need to manage a centralized file store.&lt;/p&gt;

&lt;p&gt;Anyway, the interface is very simple:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public interface &lt;/span&gt;&lt;span style="color: #2b91af"&gt;IAssetStorageManager
&lt;/span&gt;{
    &lt;span style="color: blue"&gt;void &lt;/span&gt;Delete(&lt;span style="color: blue"&gt;string &lt;/span&gt;fileUrl);
    &lt;span style="color: blue"&gt;string &lt;/span&gt;Save(System.IO.&lt;span style="color: #2b91af"&gt;FileInfo &lt;/span&gt;file);
    &lt;span style="color: blue"&gt;string &lt;/span&gt;Save(&lt;span style="color: blue"&gt;string &lt;/span&gt;fileName, System.IO.&lt;span style="color: #2b91af"&gt;Stream &lt;/span&gt;fileStream);
}&lt;/pre&gt;

&lt;p&gt;There is a factory that will give you the particular storage manager framework depending on configuration (all configuration is saved in a Sharepoint list, and the &lt;a href="http://spconfigstore.codeplex.com/"&gt;Sharepoint Config Store&lt;/a&gt; is used for retrieving it). Here is part of the factory code: &lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;AssetStorageFactory
&lt;/span&gt;{    …
    &lt;span style="color: blue"&gt;static public &lt;/span&gt;&lt;span style="color: #2b91af"&gt;IAssetStorageManager &lt;/span&gt;GetStorageManager(&lt;span style="color: blue"&gt;string &lt;/span&gt;configCategory,&lt;span style="color: blue"&gt;string &lt;/span&gt;webUrl)
    {
        &lt;span style="color: blue"&gt;var &lt;/span&gt;configHelper = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;ConfigHelper&lt;/span&gt;(webUrl);
        &lt;span style="color: blue"&gt;string &lt;/span&gt;storageMethod = configHelper.GetValue(configCategory, StorageMethodConfigKey);
        &lt;span style="color: blue"&gt;if &lt;/span&gt;(&lt;span style="color: #a31515"&gt;&amp;quot;SPLibrary&amp;quot;&lt;/span&gt;.Equals(storageMethod, &lt;span style="color: #2b91af"&gt;StringComparison&lt;/span&gt;.InvariantCultureIgnoreCase))
        {
            &lt;span style="color: blue"&gt;return new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;SPLibraryAssetStorageManager&lt;/span&gt;(webUrl, mediaLibraryName);
        }
        &lt;span style="color: blue"&gt;else if &lt;/span&gt;(&lt;span style="color: #a31515"&gt;&amp;quot;FileSystem&amp;quot;&lt;/span&gt;.Equals(storageMethod, &lt;span style="color: #2b91af"&gt;StringComparison&lt;/span&gt;.InvariantCultureIgnoreCase))
        {
            &lt;span style="color: blue"&gt;return new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;FileSystemAssetStorageManager&lt;/span&gt;(storageFolderPath,storageBaseAddress);
        }   
        &lt;span style="color: blue"&gt;else if &lt;/span&gt;(&lt;span style="color: #a31515"&gt;&amp;quot;FTP&amp;quot;&lt;/span&gt;.Equals(storageMethod, &lt;span style="color: #2b91af"&gt;StringComparison&lt;/span&gt;.InvariantCultureIgnoreCase))
        {
            &lt;span style="color: blue"&gt;return new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;FTPAssetStorageManager&lt;/span&gt;(ftpServerUrl,ftpServerPullAdress,ftpServerUsername,ftpServerPassword);
        }
        &lt;span style="color: blue"&gt;throw new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;ArgumentException&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;String&lt;/span&gt;.Format(&lt;span style="color: #a31515"&gt;&amp;quot;Incorrect configuration Value '{0}' in ConfigStore for category '{1}' and key '{2}'. Supported options are: '{3}'&amp;quot;&lt;/span&gt;,
            storageMethod, configCategory, StorageMethodConfigKey, &lt;span style="color: #a31515"&gt;&amp;quot;FileSystem|FTP|SPLibrary&amp;quot;&lt;/span&gt;));
    }       
}
&lt;br /&gt;&lt;/pre&gt;

&lt;p&gt;The implementation for a particular flavor is simple. For example, this is how the FTPAssetStorageManager saves a file stream:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public string &lt;/span&gt;Save(&lt;span style="color: blue"&gt;string &lt;/span&gt;fileName, System.IO.&lt;span style="color: #2b91af"&gt;Stream &lt;/span&gt;fileStream)
{
    &lt;span style="color: blue"&gt;string &lt;/span&gt;fileUrl = ftpServerUrl + fileName;
    &lt;span style="color: #2b91af"&gt;FtpWebRequest &lt;/span&gt;request = (&lt;span style="color: #2b91af"&gt;FtpWebRequest&lt;/span&gt;)&lt;span style="color: #2b91af"&gt;WebRequest&lt;/span&gt;.Create(fileUrl);
    request.Method = &lt;span style="color: #2b91af"&gt;WebRequestMethods&lt;/span&gt;.&lt;span style="color: #2b91af"&gt;Ftp&lt;/span&gt;.UploadFile;
    request.Credentials = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;NetworkCredential&lt;/span&gt;(username, password);
    &lt;span style="color: blue"&gt;using &lt;/span&gt;(&lt;span style="color: #2b91af"&gt;Stream &lt;/span&gt;ftpStream = request.GetRequestStream())
    {
        &lt;span style="color: #2b91af"&gt;FileUtils&lt;/span&gt;.CopyStream(fileStream, ftpStream);
    }
    &lt;span style="color: blue"&gt;return &lt;/span&gt;pullBaseAddress + fileName;
}&lt;/pre&gt;


&lt;p&gt;And this is how the storage manager is invoked from the Upload form or the Timer Job:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: green"&gt;//save to final location
&lt;/span&gt;&lt;span style="color: #2b91af"&gt;IAssetStorageManager &lt;/span&gt;storage = &lt;span style="color: #2b91af"&gt;AssetStorageFactory&lt;/span&gt;.GetStorageManager(&lt;span style="color: #a31515"&gt;&amp;quot;Media&amp;quot;&lt;/span&gt;, web.Url);
asset.Location = storage.Save(newFileUniqueName, fileInputStream);&lt;/pre&gt;


&lt;h4&gt;Conclusion&lt;/h4&gt;

&lt;p&gt;Having talked about the most important parts of the Media Processing Component for Sharepoint, I think I’m done here. The code is too much to show everything in a post, but I’ve chosen the most important parts. I might dig deeper in some other post. I will probably write about how to display videos in a web page, too.&lt;/p&gt;

&lt;p&gt;The interesting part is that even if this whole component doesn’t apply to another project, maybe some of its pieces can be reused, like the video encoding thing, or the custom upload form and storage manager to save files outside Sharepoint. So I hope it results useful to someone else! &lt;/p&gt;</description><pubDate>Thu, 12 Jan 2012 16:50:00 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/spano/media-processing-component-for-sharepoint</guid><category>Sharepoint</category></item><item><title>Sharepoint Upload File Error: ‘The remote server returned an error: (409) Conflict’</title><link>https://weblogs.asp.net:443/spano/sharepoint-upload-file-error-the-remote-server-returned-an-error-409-conflict</link><description>
&lt;p&gt;I’ve been using the following code to upload a file to a Sharepoint document library using the Client Object Model:&lt;/p&gt;
  

&lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt;
&lt;div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px"&gt;Code Snippet&lt;/div&gt;
&lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt;
&lt;ol start="1" style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;"&gt;
&lt;li&gt; &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; Save(&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; fileName, Stream fileStream)&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; destinationUrl = String.Concat(serverRelativeLibraryUrl, &lt;span style="color:#a31515"&gt;"/"&lt;/span&gt;, fileName);&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ClientContext clientContext = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; ClientContext(webUrl);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Microsoft.SharePoint.Client.File.SaveBinaryDirect(clientContext, destinationUrl, fileStream, &lt;span style="color:#0000ff"&gt;true&lt;/span&gt;);&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color:#0000ff"&gt;return&lt;/span&gt; destinationUrl;&lt;/li&gt;
&lt;li style="background: #f3f3f3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/div&gt;
  
&lt;p&gt;where &lt;/p&gt;
 serverRelativeLibraryUrl = String.Concat(webRelativeUrl, libraryName);   &lt;br&gt;  
&lt;p&gt;But I kept getting the 409 Conflict Error:&lt;/p&gt;
  
&lt;p&gt;ExceptionType: 'WebException'&amp;nbsp; ExceptionMessage: 'The remote server returned an error: (409) Conflict.'&amp;nbsp;&amp;nbsp; StackTrace: '&amp;nbsp; &lt;br&gt;at System.Net.HttpWebRequest.GetResponse()&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br&gt;at Microsoft.SharePoint.Client.SPWebRequestExecutor.Execute()&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br&gt;at Microsoft.SharePoint.Client.File.SaveBinary(ClientContext context, String serverRelativeUrl, Stream stream, String etag, Boolean overwriteIfExists, SaveBinaryCheckMode checkMode)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br&gt;at Microsoft.SharePoint.Client.File.SaveBinaryDirect(ClientContext context, String serverRelativeUrl, Stream stream, Boolean overwriteIfExists)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br&gt;&lt;/p&gt;
  
&lt;p&gt;After struggling for a while, I figured out that the problem was the library name. It contained a dash on it, like “My-LibraryName”. When I renamed it without the dash it started working. &lt;/p&gt;
  
&lt;p&gt;The error in the code is how I built the URL. I was using the library name to build the library URL, but it seems that Sharepoint doesn’t like some characters in the URL, so when you create a library called “My-LibraryName”, the URL is actually &lt;a href="http://%3Cserver%3E/MyLibraryName" mce_href="http://&amp;lt;server&amp;gt;/MyLibraryName"&gt;http://&amp;lt;server&amp;gt;/MyLibraryName&lt;/a&gt;, without the dash. &lt;/p&gt;
  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:67c82d94-41ce-45d5-80c3-5115aac94f6b" class="wlWriterEditableSmartContent"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/Sharepoint" mce_href="http://technorati.com/tags/Sharepoint" rel="tag"&gt;Sharepoint&lt;/a&gt;&lt;/div&gt;</description><pubDate>Thu, 15 Dec 2011 12:51:00 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/spano/sharepoint-upload-file-error-the-remote-server-returned-an-error-409-conflict</guid><category>Sharepoint</category></item><item><title>Sharepoint @ Buenos Aires Codecamp 2011</title><link>https://weblogs.asp.net:443/spano/sharepoint-buenos-aires-codecamp-2011</link><description>&lt;p&gt;BA Codecamp 2011 is coming soon and &lt;a href="http://www.tellago.com" mce_href="http://www.tellago.com"&gt;Tellago&lt;/a&gt; is going to be &lt;a href="http://www.codecamp.com.ar/sponsors#platino" mce_href="http://www.codecamp.com.ar/sponsors#platino"&gt;part of it&lt;/a&gt;! More than 10 architects from our team will be presenting the most innovative technology sessions on next October 15. I’m very happy to be speaking at this event! Along with my colleague Mariano Escurra, we will be presenting Best Practices using Javascript and JQuery in Sharepoint 2010. Bellow is the abstract. Register!!&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;i&gt;Mejores prácticas utilizando Javascript y JQuery en SharePoint 2010        &lt;br&gt;&lt;/i&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;i&gt;El uso de Javascript es una parte importante en la construcción de cualquier sitio web interactivo, siendo JQuery una de las bibliotecas Javascript más utilizadas. Al crear este tipo de sitios sobre SharePoint 2010, los desarrolladores pueden combinar el uso esta biblioteca con el modelo de objetos cliente Javascript (ECMAScript) mejorando notablemente la experiencia del usuario final.      &lt;br&gt;Durante esta charla abordaremos los aspectos más importantes del modelo de objetos cliente ECMAScript de SharePoint 2010 y su integración con JQuery siguiendo las mejores prácticas.&lt;/i&gt;&lt;/p&gt; &lt;a href="https://msevents.microsoft.com/CUI/EventDetail.aspx?EventID=1032493728&amp;amp;Culture=es-AR" mce_href="https://msevents.microsoft.com/CUI/EventDetail.aspx?EventID=1032493728&amp;amp;Culture=es-AR" target="_blank"&gt;&lt;img src="http://www.codecamp.com.ar/themes/codecamp/content/media/misc/ban_ar-uru_codecamp_587x293.jpg" style="width: 587px; height: 293px" alt="Banner CodeCamp 587x293" mce_src="http://www.codecamp.com.ar/themes/codecamp/content/media/misc/ban_ar-uru_codecamp_587x293.jpg"&gt; &lt;/a&gt;</description><pubDate>Wed, 21 Sep 2011 03:44:00 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/spano/sharepoint-buenos-aires-codecamp-2011</guid><category>CodeCamp</category><category>JQuery</category><category>Sharepoint</category></item><item><title>Fixing Sharepoint’s “Cannot connect to the configuration database” error</title><link>https://weblogs.asp.net:443/spano/fixing-sharepoint-s-cannot-connect-to-the-configuration-database-error</link><description>&lt;p&gt;I have Sharepoint Server 2010 installed in my development environment. It happened a couple of times that the computer hangs and the Sharepoint Configuration dabatase remains in a corrupted state. When I try to access the Sharepoint local site from the browser it gives the following error:&lt;/p&gt;  &lt;table border="1" cellspacing="0" cellpadding="2" width="510"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="508"&gt;         &lt;h4&gt;&lt;i&gt;Cannot connect to the configuration database.&lt;/i&gt;&lt;/h4&gt;         &lt;b&gt;Description: &lt;/b&gt;An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.           &lt;br /&gt;&lt;b&gt;Exception Details: &lt;/b&gt;Microsoft.SharePoint.WebPartPages.WebPartPageUserException: Cannot connect to the configuration database.&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;So, how did I fix it?&lt;/p&gt;  &lt;p&gt;I first used this &lt;a href="http://archive.msdn.microsoft.com/addselftosqlsysadmin/Release/ProjectReleases.aspx?ReleaseId=3954"&gt;addselftosqlsysadmin.cmd&lt;/a&gt; script to add my account to the SQLServer &lt;strong&gt;sysadmin&lt;/strong&gt; group.&lt;/p&gt;  &lt;p&gt;Then performed the following commands from SQL Server Management Studio:&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;select state_desc from master.sys.databases where name = 'SharePoint_Config_5ffca14b-db6f-4b30-9dd8-8317ee0f4f45'&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;The result was: &lt;strong&gt;SUSPECT&lt;/strong&gt;, confirming we had a problem.&lt;/p&gt;  &lt;p&gt;Then run:&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;ALTER DATABASE [SharePoint_Config_5ffca14b-db6f-4b30-9dd8-8317ee0f4f45]&amp;#160; SET EMERGENCY;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;GO&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;ALTER DATABASE [SharePoint_Config_5ffca14b-db6f-4b30-9dd8-8317ee0f4f45]&amp;#160; SET SINGLE_USER;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;GO&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;DBCC CHECKDB ([SharePoint_Config_5ffca14b-db6f-4b30-9dd8-8317ee0f4f45] , REPAIR_ALLOW_DATA_LOSS) WITH NO_INFOMSGS, ALL_ERRORMSGS;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;GO&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;ALTER DATABASE [SharePoint_Config_5ffca14b-db6f-4b30-9dd8-8317ee0f4f45]&amp;#160; SET MULTI_USER;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;GO&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;That’s it! I run the &lt;strong&gt;state_desc&lt;/strong&gt; command again and this time it says: &lt;strong&gt;ONLINE&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Solved!&lt;/p&gt;</description><pubDate>Fri, 17 Jun 2011 13:34:12 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/spano/fixing-sharepoint-s-cannot-connect-to-the-configuration-database-error</guid><category>Sharepoint</category></item><item><title>Azure Bootcamp @MS Argentina</title><link>https://weblogs.asp.net:443/spano/azure-bootcamp-ms-argentina</link><description>&lt;p&gt;I participated yesterday in the Azure Bootcamp that took place at 
Microsoft Argentina. Along with Vanesa Guccione, my colleague at Lagash,
 we talked about advanced roles. The contents of the presentation included the new features of the platform, such as full IIS mode, startup tasks, remote desktop plugin and local storage. We also talked about input and internal endpoints and inter-role communication, showing some demo code as well. You can download the material from &lt;a href="https://aspblogs.blob.core.windows.net/media/spano/Media/AzureBootcamp-AdvancedRoles.zip" title="here" mce_href="https://aspblogs.blob.core.windows.net/media/spano/Media/AzureBootcamp-AdvancedRoles.zip"&gt;here&lt;/a&gt;.&lt;br&gt;&lt;/p&gt;</description><pubDate>Thu, 31 Mar 2011 21:52:00 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/spano/azure-bootcamp-ms-argentina</guid><category>Azure</category></item><item><title>How to find Visual Studio command bars</title><link>https://weblogs.asp.net:443/spano/how-to-find-visual-studio-command-bars</link><description>&lt;p&gt;When developing a Visual Studio Addin it is a common task to add custom commands to existing menus and toolbars. It is a common problem too, not to find the proper command bar (we have to traverse all command bars to see its names, the names are not unique, etc). In these two posts: &lt;a href="http://blogs.msdn.com/dr._ex/archive/2007/04/17/using-ivsproffercommands-to-retrieve-a-visual-studio-commandbar.aspx" mce_href="http://blogs.msdn.com/dr._ex/archive/2007/04/17/using-ivsproffercommands-to-retrieve-a-visual-studio-commandbar.aspx"&gt;Using IVsProfferCommands to retrieve a Visual Studio CommandBar&lt;/a&gt; and&amp;nbsp; &lt;a href="http://blogs.msdn.com/dr._ex/archive/2007/04/17/using-enablevsiplogging-to-identify-menus-and-commands-with-vs-2005-sp1.aspx" mce_href="http://blogs.msdn.com/dr._ex/archive/2007/04/17/using-enablevsiplogging-to-identify-menus-and-commands-with-vs-2005-sp1.aspx"&gt;Using EnableVSIPLogging to identify menus and commands with VS 2005 + SP1&lt;/a&gt; it is very well explained how to solve this problem.&lt;/p&gt;  &lt;p&gt;The answer relies on the fact that every toolbar and menu is uniquely identified in Visual Studio by a &lt;b&gt;GUID,&lt;/b&gt;&lt;b&gt;Id&lt;/b&gt; pair. In order to see which is the GUID, Id pair for a given command, you must:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Add or change the registry key HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\9.0\General\EnableVSIPLogging to 1.&lt;/li&gt; &lt;/ul&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;img src="http://weblogs.asp.net/blogs/spano/VSCommandRegKey.png" mce_src="https://aspblogs.blob.core.windows.net/media/spano/Media/VSCommandRegKey.png"&gt; &lt;/p&gt; &lt;/blockquote&gt;  &lt;ul&gt;   &lt;li&gt;Click on the toolbar or menu you want identify while keeping CTRL+SHIFT pressed. This will show a dialog with the command bar properties. Take note of the &lt;b&gt;Guid&lt;/b&gt; and the &lt;b&gt;CmdID&lt;/b&gt;:&lt;/li&gt; &lt;/ul&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;img src="http://weblogs.asp.net/blogs/spano/VSCommandGuid.png" mce_src="https://aspblogs.blob.core.windows.net/media/spano/Media/VSCommandGuid.png"&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;ul&gt;   &lt;li&gt;From the Addin, use the following code to add your command in the desired command bar:&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&amp;nbsp;&lt;/p&gt;  &lt;blockquote&gt;   &lt;p class="MsoNormal" style="margin-top: 0in; line-height: normal;"&gt;&lt;span style="font-size: 10pt; color: blue;" courier="" new="" ;="" mso-no-proof:="" yes=""&gt;private&lt;/span&gt;&lt;span style="font-size: 10pt;" courier="" new="" ;="" mso-no-proof:="" yes=""&gt; &lt;span style="color: blue;"&gt;void&lt;/span&gt; AddMyCustomCommand()        &lt;p&gt;&amp;nbsp;&lt;/p&gt;     &lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoNormal" style="margin-top: 0in; line-height: normal;"&gt;&lt;span style="font-size: 10pt;" courier="" new="" ;="" mso-no-proof:="" yes=""&gt;{&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoNormal" style="margin-top: 0in; line-height: normal;"&gt;&lt;span style="font-size: 10pt;" courier="" new="" ;="" mso-no-proof:="" yes=""&gt;&lt;/span&gt;&lt;span style="font-size: 10pt;" courier="" new="" ;="" mso-no-proof:="" yes=""&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;…&lt;/span&gt;&lt;span style="font-size: 10pt;" courier="" new="" ;="" mso-no-proof:="" yes=""&gt;       &lt;p&gt;&amp;nbsp;&lt;/p&gt;     &lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoNormal" style="margin-top: 0in; line-height: normal;"&gt;     &lt;/p&gt;&lt;p class="MsoNormal" style="margin-top: 0in; line-height: normal;"&gt;&lt;span style="font-size: 10pt;" courier="" new="" ;="" mso-no-proof:="" yes=""&gt;         &lt;p&gt;&amp;nbsp;&lt;/p&gt;       &lt;/span&gt;&lt;/p&gt;     &lt;span style="font-size: 10pt; color: blue;" courier="" new="" ;="" mso-no-proof:="" yes=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; object&lt;/span&gt;&lt;span style="font-size: 10pt;" courier="" new="" ;="" mso-no-proof:="" yes=""&gt;[] contextGuids = &lt;span style="color: blue;"&gt;new&lt;/span&gt; &lt;span style="color: blue;"&gt;object&lt;/span&gt;[0];        &lt;p&gt;&amp;nbsp;&lt;/p&gt;     &lt;/span&gt;    &lt;p class="MsoNormal" style="margin-top: 0in; line-height: normal;"&gt;&lt;span style="font-size: 10pt;" courier="" new="" ;="" mso-no-proof:="" yes=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; myCommand = ((&lt;span style="color: rgb(43, 145, 175);"&gt;Commands2&lt;/span&gt;)&lt;span style="color: blue;"&gt;this&lt;/span&gt;._applicationObject.Commands).AddNamedCommand2(&lt;span style="color: blue;"&gt;this&lt;/span&gt;._addInInstance,&amp;nbsp; &lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoNormal" style="margin-top: 0in; line-height: normal;"&gt;&lt;span style="font-size: 10pt;" courier="" new="" ;="" mso-no-proof:="" yes=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; partialCommandName,&lt;/span&gt;&lt;span style="font-size: 10pt;" courier="" new="" ;="" mso-no-proof:="" yes=""&gt;displayName, tooltip, &lt;span style="color: blue;"&gt;true&lt;/span&gt;, &lt;span style="color: blue;"&gt;null&lt;/span&gt;, &lt;span style="color: blue;"&gt;ref&lt;/span&gt; contextGuids,        &lt;p&gt;&amp;nbsp;&lt;/p&gt;     &lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoNormal" style="margin-top: 0in; line-height: normal;"&gt;&lt;span style="font-size: 10pt;" courier="" new="" ;="" mso-no-proof:="" yes=""&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(&lt;span style="color: blue;"&gt;int&lt;/span&gt;)&lt;span style="color: rgb(43, 145, 175);"&gt;vsCommandStatus&lt;/span&gt;.vsCommandStatusSupported + (&lt;span style="color: blue;"&gt;int&lt;/span&gt;)&lt;span style="color: rgb(43, 145, 175);"&gt;vsCommandStatus&lt;/span&gt;.vsCommandStatusEnabled,        &lt;p&gt;&amp;nbsp;&lt;/p&gt;     &lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoNormal" style="margin-top: 0in; line-height: normal;"&gt;&lt;span style="font-size: 10pt;" courier="" new="" ;="" mso-no-proof:="" yes=""&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;(&lt;span style="color: blue;"&gt;int&lt;/span&gt;)&lt;span style="color: rgb(43, 145, 175);"&gt;vsCommandStyle&lt;/span&gt;.vsCommandStyleText,&lt;/span&gt;&lt;span style="font-size: 10pt;" courier="" new="" ;="" mso-no-proof:="" yes=""&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;vsCommandControlType&lt;/span&gt;.vsCommandControlTypeButton);        &lt;p&gt;&amp;nbsp;&lt;/p&gt;     &lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoNormal" style="margin-top: 0in; line-height: normal;"&gt;&lt;span style="font-size: 10pt;" courier="" new="" ;="" mso-no-proof:="" yes=""&gt;&lt;b&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CommandBar&lt;/span&gt; ownerBar = FindCommandBar(&lt;span style="color: blue;"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;Guid&lt;/span&gt;(&lt;span style="color: rgb(163, 21, 21);"&gt;"{9AEB9524-82C6-40B9-9285-8D85D3DBD4C4}"&lt;/span&gt;), 1280); &lt;span style="color: green;"&gt;           &lt;p&gt;&amp;nbsp;&lt;/p&gt;         &lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoNormal" style="margin-top: 0in; line-height: normal;"&gt;&lt;span style="font-size: 10pt;" courier="" new="" ;="" mso-no-proof:="" yes=""&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;myControl = workflowCommand.AddControl(ownerBar, 1) &lt;span style="color: blue;"&gt;as&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;CommandBarButton&lt;/span&gt;;&lt;/span&gt;&lt;span style="font-size: 10pt;" courier="" new="" ;="" mso-no-proof:="" yes=""&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; line-height: 115%;" courier="" new="" ;="" mso-no-proof:="" yes=""&gt;}&lt;/span&gt;&lt;/p&gt;    &lt;p&gt;&amp;nbsp;&lt;/p&gt;    &lt;p class="MsoNormal" style="margin-top: 0in; line-height: normal;"&gt;&lt;span style="font-size: 10pt; color: blue;" courier="" new="" ;="" mso-no-proof:="" yes=""&gt;private&lt;/span&gt;&lt;span style="font-size: 10pt;" courier="" new="" ;="" mso-no-proof:="" yes=""&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;CommandBar&lt;/span&gt; FindCommandBar(&lt;span style="color: rgb(43, 145, 175);"&gt;Guid&lt;/span&gt; guidCmdGroup, &lt;span style="color: blue;"&gt;uint&lt;/span&gt; menuID)        &lt;p&gt;&amp;nbsp;&lt;/p&gt;     &lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoNormal" style="margin-top: 0in; line-height: normal;"&gt;&lt;span style="font-size: 10pt;" courier="" new="" ;="" mso-no-proof:="" yes=""&gt;{       &lt;p&gt;&amp;nbsp;&lt;/p&gt;     &lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoNormal" style="margin-top: 0in; line-height: normal;"&gt;&lt;span style="font-size: 10pt;" courier="" new="" ;="" mso-no-proof:="" yes=""&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color: green;"&gt;// Retrieve IVsProfferComands via DTE's IOleServiceProvider interface         &lt;p&gt;&amp;nbsp;&lt;/p&gt;       &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoNormal" style="margin-top: 0in; line-height: normal;"&gt;&lt;span style="font-size: 10pt;" courier="" new="" ;="" mso-no-proof:="" yes=""&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;IOleServiceProvider&lt;/span&gt; sp = (&lt;span style="color: rgb(43, 145, 175);"&gt;IOleServiceProvider&lt;/span&gt;)_applicationObject;        &lt;p&gt;&amp;nbsp;&lt;/p&gt;     &lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoNormal" style="margin-top: 0in; line-height: normal;"&gt;&lt;span style="font-size: 10pt;" courier="" new="" ;="" mso-no-proof:="" yes=""&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;Guid&lt;/span&gt; guidSvc = &lt;span style="color: blue;"&gt;typeof&lt;/span&gt;(&lt;span style="color: rgb(43, 145, 175);"&gt;IVsProfferCommands&lt;/span&gt;).GUID;        &lt;p&gt;&amp;nbsp;&lt;/p&gt;     &lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoNormal" style="margin-top: 0in; line-height: normal;"&gt;&lt;span style="font-size: 10pt;" courier="" new="" ;="" mso-no-proof:="" yes=""&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;Object&lt;/span&gt; objService;        &lt;p&gt;&amp;nbsp;&lt;/p&gt;     &lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoNormal" style="margin-top: 0in; line-height: normal;"&gt;&lt;span style="font-size: 10pt;" courier="" new="" ;="" mso-no-proof:="" yes=""&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;sp.QueryService(&lt;span style="color: blue;"&gt;ref&lt;/span&gt; guidSvc, &lt;span style="color: blue;"&gt;ref&lt;/span&gt; guidSvc, &lt;span style="color: blue;"&gt;out&lt;/span&gt; objService);        &lt;p&gt;&amp;nbsp;&lt;/p&gt;     &lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoNormal" style="margin-top: 0in; line-height: normal;"&gt;&lt;span style="font-size: 10pt;" courier="" new="" ;="" mso-no-proof:="" yes=""&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;IVsProfferCommands&lt;/span&gt; vsProfferCmds = (&lt;span style="color: rgb(43, 145, 175);"&gt;IVsProfferCommands&lt;/span&gt;)objService;        &lt;p&gt;&amp;nbsp;&lt;/p&gt;     &lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoNormal" style="margin-top: 0in; line-height: normal;"&gt;&lt;span style="font-size: 10pt;" courier="" new="" ;="" mso-no-proof:="" yes=""&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color: blue;"&gt;return&lt;/span&gt; vsProfferCmds.FindCommandBar(&lt;span style="color: rgb(43, 145, 175);"&gt;IntPtr&lt;/span&gt;.Zero, &lt;span style="color: blue;"&gt;ref&lt;/span&gt; guidCmdGroup, menuID) &lt;span style="color: blue;"&gt;as&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;CommandBar&lt;/span&gt;;        &lt;p&gt;&amp;nbsp;&lt;/p&gt;     &lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; line-height: 115%;" courier="" new="" ;="" mso-no-proof:="" yes=""&gt;}&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; line-height: 115%;" courier="" new="" ;="" mso-no-proof:="" yes=""&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoNormal" style="margin-top: 0in; line-height: normal;"&gt;&lt;span style="font-size: 10pt;" courier="" new="" ;="" mso-no-proof:="" yes=""&gt;[&lt;span style="color: rgb(43, 145, 175);"&gt;ComImport&lt;/span&gt;,&lt;span style="color: rgb(43, 145, 175);"&gt;Guid&lt;/span&gt;(&lt;span style="color: rgb(163, 21, 21);"&gt;"6D5140C1-7436-11CE-8034-00AA006009FA"&lt;/span&gt;),        &lt;p&gt;&amp;nbsp;&lt;/p&gt;     &lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoNormal" style="margin-top: 0in; line-height: normal;"&gt;&lt;span style="font-size: 10pt; color: rgb(43, 145, 175);" courier="" new="" ;="" mso-no-proof:="" yes=""&gt;InterfaceTypeAttribute&lt;/span&gt;&lt;span style="font-size: 10pt;" courier="" new="" ;="" mso-no-proof:="" yes=""&gt;(&lt;span style="color: rgb(43, 145, 175);"&gt;ComInterfaceType&lt;/span&gt;.InterfaceIsIUnknown)]        &lt;p&gt;&amp;nbsp;&lt;/p&gt;     &lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoNormal" style="margin-top: 0in; line-height: normal;"&gt;&lt;span style="font-size: 10pt; color: blue;" courier="" new="" ;="" mso-no-proof:="" yes=""&gt;internal&lt;/span&gt;&lt;span style="font-size: 10pt;" courier="" new="" ;="" mso-no-proof:="" yes=""&gt; &lt;span style="color: blue;"&gt;interface&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;IOleServiceProvider         &lt;p&gt;&amp;nbsp;&lt;/p&gt;       &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoNormal" style="margin-top: 0in; line-height: normal;"&gt;&lt;span style="font-size: 10pt;" courier="" new="" ;="" mso-no-proof:="" yes=""&gt;{       &lt;p&gt;&amp;nbsp;&lt;/p&gt;     &lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoNormal" style="margin-top: 0in; line-height: normal;"&gt;&lt;span style="font-size: 10pt;" courier="" new="" ;="" mso-no-proof:="" yes=""&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;[&lt;span style="color: rgb(43, 145, 175);"&gt;PreserveSig&lt;/span&gt;]        &lt;p&gt;&amp;nbsp;&lt;/p&gt;     &lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoNormal" style="margin-top: 0in; line-height: normal;"&gt;&lt;span style="font-size: 10pt;" courier="" new="" ;="" mso-no-proof:="" yes=""&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color: blue;"&gt;int&lt;/span&gt; QueryService([&lt;span style="color: rgb(43, 145, 175);"&gt;In&lt;/span&gt;]&lt;span style="color: blue;"&gt;ref&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;Guid&lt;/span&gt; guidService, [&lt;span style="color: rgb(43, 145, 175);"&gt;In&lt;/span&gt;]&lt;span style="color: blue;"&gt;ref&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;Guid&lt;/span&gt; riid,        &lt;p&gt;&amp;nbsp;&lt;/p&gt;     &lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoNormal" style="margin-top: 0in; line-height: normal;"&gt;&lt;span style="font-size: 10pt;" courier="" new="" ;="" mso-no-proof:="" yes=""&gt;&lt;span style=""&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;[&lt;span style="color: rgb(43, 145, 175);"&gt;MarshalAs&lt;/span&gt;(&lt;span style="color: rgb(43, 145, 175);"&gt;UnmanagedType&lt;/span&gt;.Interface)] &lt;span style="color: blue;"&gt;out&lt;/span&gt; System.&lt;span style="color: rgb(43, 145, 175);"&gt;Object&lt;/span&gt; obj);        &lt;p&gt;&amp;nbsp;&lt;/p&gt;     &lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; line-height: 115%;" courier="" new="" ;="" mso-no-proof:="" yes=""&gt;}&lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt;</description><pubDate>Tue, 07 Oct 2008 14:07:00 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/spano/how-to-find-visual-studio-command-bars</guid><category>Visual Studio</category></item><item><title>CodeCamp Buenos Aires 2008</title><link>https://weblogs.asp.net:443/spano/codecamp-buenos-aires-2008</link><description>&lt;p&gt;I attended yesterday to the &lt;a href="http://www.microsoft.com/argentina/codecamp/"&gt;Microsoft Code Camp&lt;/a&gt; event at Buenos Aires. It was fun! &lt;/p&gt;  &lt;p&gt;Here's a picture of the &lt;a href="http://www.lagash.com/"&gt;Lagash&lt;/a&gt; stand:&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;img src="https://aspblogs.blob.core.windows.net/media/spano/Media/CodeCamp04.JPG" /&gt;&lt;/p&gt;</description><pubDate>Sun, 05 Oct 2008 14:13:18 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/spano/codecamp-buenos-aires-2008</guid></item><item><title>UI Automation Article Published on Level Extreme</title><link>https://weblogs.asp.net:443/spano/ui-automation-article-published-on-level-extreme</link><description>

&lt;p&gt;On this month's edition of the  &lt;a href="http://www.levelextreme.net/" mce_href="http://www.levelextreme.net/"&gt;Level Extreme .Net Magazine&lt;/a&gt;, my article about &lt;a href="http://www.levelextreme.net/ViewPageArticle.aspx?Session=3143664868567841524F303D2031476A37344564662F76543075542F4C2B70546C34513D3D" mce_href="http://www.levelextreme.net/ViewPageArticle.aspx?Session=3143664868567841524F303D2031476A37344564662F76543075542F4C2B70546C34513D3D"&gt;Building an UI Automation Client Application&lt;/a&gt; was published.  The article walks through building a client application for automating a win 32 target application (the Windows Address Book). The idea is to show through simple code snippets how to use the &lt;a href="http://weblogs.asp.net/spano/archive/2007/09/07/wpf-accessibility.aspx" mce_href="http://weblogs.asp.net/spano/archive/2007/09/07/wpf-accessibility.aspx"&gt;UI Automation&lt;/a&gt; API for manipulating a target application programmatically through its UI. It shows how to find the UI elements, and how to work with the UI Automation patterns and handle events. The sample client application code contains further examples and can be downloaded from the article's page. Hope you read it!&lt;/p&gt;&lt;p&gt;&lt;img src="https://aspblogs.blob.core.windows.net/media/spano/Media/LevelExtremeMarch2008.jpg" title="March edition Level Extreme" alt="March edition Level Extreme" mce_src="https://aspblogs.blob.core.windows.net/media/spano/Media/LevelExtremeMarch2008.jpg" height="172" width="134"&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Read more on the magazine from &lt;a href="http://blog.salias.com.ar/2008/03/level-extreme-net-de-marzo.html" mce_href="http://blog.salias.com.ar/2008/03/level-extreme-net-de-marzo.html"&gt;Martin Salias&lt;/a&gt;.&lt;br&gt;&lt;/p&gt;
</description><pubDate>Wed, 12 Mar 2008 17:38:00 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/spano/ui-automation-article-published-on-level-extreme</guid><category>WPF</category></item><item><title>CCF: Listening to External Application Events</title><link>https://weblogs.asp.net:443/spano/ccf-listening-to-external-application-events</link><description>&lt;P&gt;It is often necessary to listen to external application UI events when automating applications in CCF. For example, we may need to save a value in the Context if the user presses a button, or do something when an alert dialog appears. There are many ways we can handle events. In CCF 2008, the Hosted Application Toolkit (HAT) provides an easy way to listen to them. If not using HAT we can hook to events using the UIAutomation or MSAA (Microsoft Active Accessibility) APIs within our own application adapters.&lt;/P&gt;
&lt;H3&gt;Events in HAT&lt;/H3&gt;
&lt;P&gt;When we configure a hosted application for using an Automation Adapter, this adapter listens to the application events. We can hook and unhook to these events using the CCF's WF activities &lt;STRONG&gt;RegisterActionForEvent&lt;/STRONG&gt; (see figure bellow)&amp;nbsp; and &lt;STRONG&gt;UnregisterActionForEvent&lt;/STRONG&gt; respectively.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;IMG src="http://weblogs.asp.net/blogs/spano/hat_registerEvent.JPG" mce_src="https://aspblogs.blob.core.windows.net/media/spano/Media/hat_registerEvent.JPG"&gt;&lt;/P&gt;
&lt;P&gt;It is the Data Driven Adapter (DDA) the one who throws the &lt;STRONG&gt;ControlChanged&lt;/STRONG&gt; event (to which the activity subscribes). The arguments of the event consists of eventTypeName, controlName and controlValue.&lt;/P&gt;
&lt;P&gt;For example, the WinDataDrivenAdapter that CCF provides supports the following event types:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;SetControlValue: When the DDA set's a control's value. &lt;/LI&gt;
&lt;LI&gt;ExecuteControlAction: When the DDA executes a control. &lt;/LI&gt;
&lt;LI&gt;ContextChanged: When the context changes. &lt;/LI&gt;
&lt;LI&gt;MenuShown: When a menu is shown &lt;/LI&gt;
&lt;LI&gt;WindowShown: When a window is shown &lt;/LI&gt;
&lt;LI&gt;WindowDisappeared: When a window is closed &lt;/LI&gt;
&lt;LI&gt;LostFocus &lt;/LI&gt;
&lt;LI&gt;SetFocus &lt;/LI&gt;
&lt;LI&gt;CheckBoxSet &lt;/LI&gt;
&lt;LI&gt;CheckBoxCleared &lt;/LI&gt;
&lt;LI&gt;RadioButtonSet &lt;/LI&gt;
&lt;LI&gt;RadioButtonCleared &lt;/LI&gt;
&lt;LI&gt;ButtonPressed &lt;/LI&gt;
&lt;LI&gt;ButtonReleased &lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;There are some tricks about how to use this events, for example: &lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;EM&gt;4-6: For menu and window events we must not register with the control's friendly name that we set in the databindings section of the AppInitString. We must specify the window or menu's caption instead.&lt;/EM&gt;&amp;nbsp; &lt;/LI&gt;
&lt;LI&gt;&lt;EM&gt;7-14: For these events the related control must be previously found on the UI. You can use the FindControl activity to ensure that the control is successfully found. When the DDA finds the control it registers it in a KnownControls collection. Only for those registered controls the events are thrown.&lt;/EM&gt; &lt;/LI&gt;&lt;/UL&gt;
&lt;H3&gt;Custom DDAs or Legacy Adapters&lt;/H3&gt;
&lt;P&gt;If we need to handle events from a custom DDA or from a legacy adapter we can use win32 or accessibility APIs. If we use a custom DDA we can throw a ControlChanged event in order to use the WF/Automation activities mentioned before.&lt;/P&gt;
&lt;H4&gt;WinEvents&lt;/H4&gt;
&lt;P&gt;A low level approach is to use the SetWinEventHook and UnhookWinEvent functions from user32.dll. When we hook for events we specify the callback function that will handle the events. You can see the list of &lt;A href="http://msdn.microsoft.com/en-us/library/ms697187(VS.85).aspx" mce_href="http://msdn.microsoft.com/en-us/library/ms697187(VS.85).aspx"&gt;supported events&lt;/A&gt; and its constants in the MSAA SDK documentation on msdn.&lt;/P&gt;
&lt;P&gt;In order to show some sample code, here are the user32 functions imports:&lt;/P&gt;
&lt;P&gt;[&lt;SPAN class=cb1&gt;Flags&lt;/SPAN&gt;]&lt;/P&gt;
&lt;DIV class=cf&gt;
&lt;P class=cl&gt;&lt;SPAN class=cb2&gt;internal&lt;/SPAN&gt; &lt;SPAN class=cb2&gt;enum&lt;/SPAN&gt; &lt;SPAN class=cb1&gt;SetWinEventHookFlags&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=cl&gt;{&lt;/P&gt;
&lt;P class=cl&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; WINEVENT_INCONTEXT = 4,&lt;/P&gt;
&lt;P class=cl&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; WINEVENT_OUTOFCONTEXT = 0,&lt;/P&gt;
&lt;P class=cl&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; WINEVENT_SKIPOWNPROCESS = 2,&lt;/P&gt;
&lt;P class=cl&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; WINEVENT_SKIPOWNTHREAD = 1&lt;/P&gt;
&lt;P class=cl&gt;}&lt;/P&gt;&lt;/DIV&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red43\green145\blue175;\red163\green21\blue21;\red0\green0\blue255;}??\fs20         [\cf3 DllImport\cf0 (\cf4 "user32.dll"\cf0 , SetLastError = \cf5 true\cf0 )]\par ??        \cf5 internal\cf0  \cf5 static\cf0  \cf5 extern\cf0  \cf3 IntPtr\cf0  SetWinEventHook(\cf5 int\cf0  eventMin, \cf5 int\cf0  eventMax, \cf3 IntPtr\cf0  hmodWinEventProc, \cf3 WinEventProc\cf0  lpfnWinEventProc, \cf5 int\cf0  idProcess, \cf5 int\cf0  idThread, \cf3 SetWinEventHookFlags\cf0  dwflags);\par ??}
--&gt;&lt;/P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: courier new"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN class=cb1&gt;internal&lt;/SPAN&gt; &lt;SPAN class=cb1&gt;delegate&lt;/SPAN&gt; &lt;SPAN class=cb1&gt;void&lt;/SPAN&gt; &lt;SPAN class=cb2&gt;WinEventProc&lt;/SPAN&gt;(&lt;SPAN class=cb2&gt;IntPtr&lt;/SPAN&gt; hWinEventHook, &lt;SPAN class=cb1&gt;int&lt;/SPAN&gt; iEvent, &lt;SPAN class=cb2&gt;IntPtr&lt;/SPAN&gt; hWnd, &lt;SPAN class=cb1&gt;int&lt;/SPAN&gt; idObject, &lt;SPAN class=cb1&gt;int&lt;/SPAN&gt; idChild, &lt;SPAN class=cb1&gt;int&lt;/SPAN&gt; dwEventThread, &lt;SPAN class=cb1&gt;int&lt;/SPAN&gt; dwmsEventTime);&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;[&lt;SPAN style="COLOR: #2b91af"&gt;DllImport&lt;/SPAN&gt;(&lt;SPAN style="COLOR: #a31515"&gt;"user32.dll"&lt;/SPAN&gt;, SetLastError = &lt;SPAN style="COLOR: blue"&gt;true&lt;/SPAN&gt;)]&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;internal&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;static&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;extern&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;IntPtr&lt;/SPAN&gt; SetWinEventHook(&lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt; eventMin, &lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt; eventMax, &lt;SPAN style="COLOR: #2b91af"&gt;IntPtr&lt;/SPAN&gt; hmodWinEventProc, &lt;SPAN style="COLOR: #2b91af"&gt;WinEventProc&lt;/SPAN&gt; lpfnWinEventProc, &lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt; idProcess, &lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt; idThread, &lt;SPAN style="COLOR: #2b91af"&gt;SetWinEventHookFlags&lt;/SPAN&gt; dwflags);&lt;/P&gt;
&lt;DIV class=cf&gt;
&lt;P class=cl&gt;[&lt;SPAN class=cb1&gt;DllImport&lt;/SPAN&gt;(&lt;SPAN class=cb2&gt;"user32.dll"&lt;/SPAN&gt;, SetLastError = &lt;SPAN class=cb3&gt;true&lt;/SPAN&gt;)]&lt;/P&gt;
&lt;P class=cl&gt;&lt;SPAN class=cb3&gt;internal&lt;/SPAN&gt; &lt;SPAN class=cb3&gt;static&lt;/SPAN&gt; &lt;SPAN class=cb3&gt;extern&lt;/SPAN&gt; &lt;SPAN class=cb3&gt;int&lt;/SPAN&gt; UnhookWinEvent(&lt;SPAN class=cb1&gt;IntPtr&lt;/SPAN&gt; hWinEventHook);&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;}??\fs20     \cf3 internal\cf0  \cf3 delegate\cf0  \cf3 void\cf0  \cf4 WinEventProc\cf0 (\cf4 IntPtr\cf0  hWinEventHook, \cf3 int\cf0  iEvent, \cf4 IntPtr\cf0  hWnd, \cf3 int\cf0  idObject, \cf3 int\cf0  idChild, \cf3 int\cf0  dwEventThread, \cf3 int\cf0  dwmsEventTime);\par ??}
--&gt;
&lt;STYLE type=text/css&gt;









.cf { font-family: courier new; font-size: 10pt; color: black; background: white; }
.cl { margin: 0px; }
.cb1 { color: blue; }
.cb2 { color: #2b91af; }&lt;/STYLE&gt;
&lt;/P&gt;
&lt;DIV class=cf&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red43\green145\blue175;\red163\green21\blue21;\red0\green0\blue255;}??\fs20 [\cf3 DllImport\cf0 (\cf4 "user32.dll"\cf0 , SetLastError = \cf5 true\cf0 )]\par ??\cf5 internal\cf0  \cf5 static\cf0  \cf5 extern\cf0  \cf5 int\cf0  UnhookWinEvent(\cf3 IntPtr\cf0  hWinEventHook);\par ??}
--&gt;
&lt;STYLE type=text/css&gt;








.cf { font-family: courier new; font-size: 10pt; color: black; background: white; }
.cl { margin: 0px; }
.cb1 { color: #2b91af; }
.cb2 { color: #a31515; }
.cb3 { color: blue; }&lt;/STYLE&gt;
&lt;/P&gt;
&lt;P&gt;&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red0\green0\blue0;\red43\green145\blue175;\red0\green128\blue0;\red163\green21\blue21;}??\fs20 \cf1 private\cf0  \cf1 void\cf0  EventCallback(\cf4 IntPtr\cf0  hWinEventHook, \cf1 int\cf0  iEvent, \cf4 IntPtr\cf0  hWnd, \cf1 int\cf0  idObject, \cf1 int\cf0  idChild, \cf1 int\cf0  dwEventThread, \cf1 int\cf0  dwmsEventTime)\par ??\{\par ??    \cf5 //get accObj from handler\par ??\cf0     \cf5 //get accObj's name, role, etc...\par ??\cf0     ...\par ??    \cf1 switch\cf0  (iEvent)\par ??    \{\par ??         \cf1 case\cf0  0x10: \cf5 //WinEvent.EVENT_SYSTEM_DIALOGSTART\par ??\cf0              \cf1 if\cf0  (role.Equals(\cf4 localize\cf0 .ACC_ROLE_TEXT_WINDOW))\par ??             \{\par ??                  \cf1 if\cf0  (name.Length &amp;gt; 0)\par ??                  \{\par ??                      \cf5 //throw ControlChangedEvent\par ??\cf0                        \cf1 this\cf0 .ControlChanged(accObj, \cf1 new\cf0  \cf4 ControlChangedEventArgs\cf0 (\cf6 "DialogStart"\cf0 , controlName, \cf1 string\cf0 .Empty));\par ??                  \}\par ??             \}\par ??             \cf1 break\cf0 ;\par ??        ...\par ??    \}\par ??\}}
--&gt;
&lt;STYLE type=text/css&gt;





.cf { font-family: courier new; font-size: 10pt; color: black; background: white; }
.cl { margin: 0px; }
.cb1 { color: blue; }
.cb2 { color: #2b91af; }
.cb3 { color: green; }
.cb4 { color: #a31515; }&lt;/STYLE&gt;
&lt;/P&gt;
&lt;P&gt;Here's how we can subscribe to win events from our custom adapter:&lt;/P&gt;
&lt;P&gt;&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red43\green145\blue175;\red255\green255\blue255;\red0\green0\blue0;\red0\green0\blue255;}??\fs20 \cf1 WinEventProc\cf0  wep = \cf4 new\cf0  \cf1 WinEventProc\cf0 (\cf4 this\cf0 .EventCallback);\par ??SetWinEventHook(1, 0x7fffffff, \cf1 IntPtr\cf0 .Zero, wep, 0, threadId, \cf1 SetWinEventHookFlags\cf0 .WINEVENT_OUTOFCONTEXT);\par ??}
--&gt;
&lt;STYLE type=text/css&gt;



.cf { font-family: courier new; font-size: 10pt; color: black; background: white; }
.cl { margin: 0px; }
.cb1 { color: #2b91af; }
.cb2 { color: blue; }&lt;/STYLE&gt;
&lt;/P&gt;
&lt;DIV class=cf&gt;
&lt;P class=cl&gt;&lt;SPAN class=cb1&gt;WinEventProc&lt;/SPAN&gt; wep = &lt;SPAN class=cb2&gt;new&lt;/SPAN&gt; &lt;SPAN class=cb1&gt;WinEventProc&lt;/SPAN&gt;(&lt;SPAN class=cb2&gt;this&lt;/SPAN&gt;.EventCallback);&lt;/P&gt;
&lt;P class=cl&gt;SetWinEventHook(1, 0x7fffffff, &lt;SPAN class=cb1&gt;IntPtr&lt;/SPAN&gt;.Zero, wep, 0, threadId, &lt;SPAN class=cb1&gt;SetWinEventHookFlags&lt;/SPAN&gt;.WINEVENT_OUTOFCONTEXT);&lt;/P&gt;&lt;/DIV&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And finally how to react to events in the event handler method: &lt;/P&gt;
&lt;DIV class=cf&gt;
&lt;P class=cl&gt;&lt;SPAN class=cb1&gt;private&lt;/SPAN&gt; &lt;SPAN class=cb1&gt;void&lt;/SPAN&gt; EventCallback(&lt;SPAN class=cb2&gt;IntPtr&lt;/SPAN&gt; hWinEventHook, &lt;SPAN class=cb1&gt;int&lt;/SPAN&gt; iEvent, &lt;SPAN class=cb2&gt;IntPtr&lt;/SPAN&gt; hWnd, &lt;SPAN class=cb1&gt;int&lt;/SPAN&gt; idObject, &lt;SPAN class=cb1&gt;int&lt;/SPAN&gt; idChild, &lt;SPAN class=cb1&gt;int&lt;/SPAN&gt; dwEventThread, &lt;SPAN class=cb1&gt;int&lt;/SPAN&gt; dwmsEventTime)&lt;/P&gt;
&lt;P class=cl&gt;{&lt;/P&gt;
&lt;P class=cl&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class=cb3&gt;//get accObj from handler&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=cl&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class=cb3&gt;//get accObj's name, role, etc...&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=cl&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ...&lt;/P&gt;
&lt;P class=cl&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class=cb1&gt;switch&lt;/SPAN&gt; (iEvent)&lt;/P&gt;
&lt;P class=cl&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P class=cl&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class=cb1&gt;case&lt;/SPAN&gt; 0x10: &lt;SPAN class=cb3&gt;//EVENT_SYSTEM_DIALOGSTART&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=cl&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class=cb1&gt;if&lt;/SPAN&gt; (role.Equals(&lt;SPAN class=cb2&gt;localize&lt;/SPAN&gt;.ACC_ROLE_TEXT_WINDOW))&lt;/P&gt;
&lt;P class=cl&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P class=cl&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class=cb1&gt;if&lt;/SPAN&gt; (name.Length &amp;gt; 0)&lt;/P&gt;
&lt;P class=cl&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P class=cl&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class=cb3&gt;//throw ControlChangedEvent&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=cl&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class=cb1&gt;this&lt;/SPAN&gt;.ControlChanged(accObj, &lt;SPAN class=cb1&gt;new&lt;/SPAN&gt; &lt;SPAN class=cb2&gt;ControlChangedEventArgs&lt;/SPAN&gt;(&lt;SPAN class=cb4&gt;"DialogStart"&lt;/SPAN&gt;, controlName, &lt;SPAN class=cb1&gt;string&lt;/SPAN&gt;.Empty));&lt;/P&gt;
&lt;P class=cl&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P class=cl&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P class=cl&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class=cb1&gt;break&lt;/SPAN&gt;;&lt;/P&gt;
&lt;P class=cl&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ...&lt;/P&gt;
&lt;P class=cl&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P class=cl&gt;}&lt;/P&gt;&lt;/DIV&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;H4&gt;UIAutomation&lt;/H4&gt;
&lt;P&gt;Another option is to use the UIAutomation accessibility API, included on .Net framework 3.0 to hook to events from custom adapters. The Automation element provides the following static methods to hook to different event on different controls:&lt;/P&gt;
&lt;P&gt;&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green128\blue0;\red0\green0\blue255;\red43\green145\blue175;}??\fs20         \cf3 // Summary:\par ??\cf0         \cf3 //     Registers a method that handles UI Automation events.\par ??\cf0         \cf3 //\par ??\cf0         \cf3 // Parameters:\par ??\cf0         \cf3 //   scope:\par ??\cf0         \cf3 //     The scope of events to be handled; that is, whether they are on the element\par ??\cf0         \cf3 //     itself, or on its ancestors and descendants.\par ??\cf0         \cf3 //\par ??\cf0         \cf3 //   eventHandler:\par ??\cf0         \cf3 //     The method to call when the specified event occurs.\par ??\cf0         \cf3 //\par ??\cf0         \cf3 //   element:\par ??\cf0         \cf3 //     The UI Automation element to associate with the event handler.\par ??\cf0         \cf3 //\par ??\cf0         \cf3 //   eventId:\par ??\cf0         \cf3 //     The identifier for the event the method will handle.\par ??\cf0         \cf4 public\cf0  \cf4 static\cf0  \cf4 void\cf0  AddAutomationEventHandler(\cf5 AutomationEvent\cf0  eventId, \cf5 AutomationElement\cf0  element, \cf5 TreeScope\cf0  scope, \cf5 AutomationEventHandler\cf0  eventHandler);\par ??        \cf3 //\par ??\cf0         \cf3 // Summary:\par ??\cf0         \cf3 //     Registers a method that will handle focus-changed events.\par ??\cf0         \cf3 //\par ??\cf0         \cf3 // Parameters:\par ??\cf0         \cf3 //   eventHandler:\par ??\cf0         \cf3 //     The method to call when the event occurs.\par ??\cf0         \cf4 public\cf0  \cf4 static\cf0  \cf4 void\cf0  AddAutomationFocusChangedEventHandler(\cf5 AutomationFocusChangedEventHandler\cf0  eventHandler);\par ??        \cf3 //\par ??\cf0         \cf3 // Summary:\par ??\cf0         \cf3 //     Registers a method that will handle property-changed events.\par ??\cf0         \cf3 //\par ??\cf0         \cf3 // Parameters:\par ??\cf0         \cf3 //   scope:\par ??\cf0         \cf3 //     The scope of events to be handled; that is, whether they are on the element\par ??\cf0         \cf3 //     itself, or on its ancestors and children.\par ??\cf0         \cf3 //\par ??\cf0         \cf3 //   properties:\par ??\cf0         \cf3 //     The UI Automation properties of interest.\par ??\cf0         \cf3 //\par ??\cf0         \cf3 //   eventHandler:\par ??\cf0         \cf3 //     The method to call when the event occurs.\par ??\cf0         \cf3 //\par ??\cf0         \cf3 //   element:\par ??\cf0         \cf3 //     The UI Automation element with which to associate the event handler.\par ??\cf0         \cf4 public\cf0  \cf4 static\cf0  \cf4 void\cf0  AddAutomationPropertyChangedEventHandler(\cf5 AutomationElement\cf0  element, \cf5 TreeScope\cf0  scope, \cf5 AutomationPropertyChangedEventHandler\cf0  eventHandler, \cf4 params\cf0  \cf5 AutomationProperty\cf0 [] properties);\par ??        \cf3 //\par ??\cf0         \cf3 // Summary:\par ??\cf0         \cf3 //     Registers the method that will handle structure-changed events.\par ??\cf0         \cf3 //\par ??\cf0         \cf3 // Parameters:\par ??\cf0         \cf3 //   scope:\par ??\cf0         \cf3 //     The scope of events to be handled; that is, whether they are on the element\par ??\cf0         \cf3 //     itself, or on its ancestors and descendants.\par ??\cf0         \cf3 //\par ??\cf0         \cf3 //   eventHandler:\par ??\cf0         \cf3 //     The method to call when the structure-changed event occurs.\par ??\cf0         \cf3 //\par ??\cf0         \cf3 //   element:\par ??\cf0         \cf3 //     The UI Automation element with which to associate the event handler.\par ??\cf0         \cf4 public\cf0  \cf4 static\cf0  \cf4 void\cf0  AddStructureChangedEventHandler(\cf5 AutomationElement\cf0  element, \cf5 TreeScope\cf0  scope, \cf5 StructureChangedEventHandler\cf0  eventHandler);\par ??}
--&gt;
&lt;STYLE type=text/css&gt;

.cf { font-family: courier new; font-size: 10pt; color: black; background: white; }
.cl { margin: 0px; }
.cb1 { color: green; }
.cb2 { color: blue; }
.cb3 { color: #2b91af; }&lt;/STYLE&gt;
&lt;/P&gt;
&lt;DIV class=cf&gt;
&lt;P class=cl&gt;&lt;SPAN class=cb1&gt;//Registers a method that handles UI Automation events.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=cl&gt;&lt;SPAN class=cb2&gt;public&lt;/SPAN&gt; &lt;SPAN class=cb2&gt;static&lt;/SPAN&gt; &lt;SPAN class=cb2&gt;void&lt;/SPAN&gt; AddAutomationEventHandler(&lt;SPAN class=cb3&gt;AutomationEvent&lt;/SPAN&gt; eventId, &lt;SPAN class=cb3&gt;AutomationElement&lt;/SPAN&gt; element, &lt;SPAN class=cb3&gt;TreeScope&lt;/SPAN&gt; scope, &lt;SPAN class=cb3&gt;AutomationEventHandler&lt;/SPAN&gt; eventHandler);&lt;/P&gt;
&lt;P class=cl&gt;&lt;SPAN class=cb1&gt;//Registers a method that will handle focus-changed events.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=cl&gt;&lt;SPAN class=cb2&gt;public&lt;/SPAN&gt; &lt;SPAN class=cb2&gt;static&lt;/SPAN&gt; &lt;SPAN class=cb2&gt;void&lt;/SPAN&gt; AddAutomationFocusChangedEventHandler(&lt;SPAN class=cb3&gt;AutomationFocusChangedEventHandler&lt;/SPAN&gt; eventHandler);&lt;/P&gt;
&lt;P class=cl&gt;&lt;SPAN class=cb1&gt;//Registers a method that will handle property-changed events.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=cl&gt;&lt;SPAN class=cb2&gt;public&lt;/SPAN&gt; &lt;SPAN class=cb2&gt;static&lt;/SPAN&gt; &lt;SPAN class=cb2&gt;void&lt;/SPAN&gt; AddAutomationPropertyChangedEventHandler(&lt;SPAN class=cb3&gt;AutomationElement&lt;/SPAN&gt; element, &lt;SPAN class=cb3&gt;TreeScope&lt;/SPAN&gt; scope, &lt;SPAN class=cb3&gt;AutomationPropertyChangedEventHandler&lt;/SPAN&gt; eventHandler, &lt;SPAN class=cb2&gt;params&lt;/SPAN&gt; &lt;SPAN class=cb3&gt;AutomationProperty&lt;/SPAN&gt;[] properties);&lt;/P&gt;
&lt;P class=cl&gt;&lt;SPAN class=cb1&gt;//Registers the method that will handle structure-changed events.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=cl&gt;&lt;SPAN class=cb2&gt;public&lt;/SPAN&gt; &lt;SPAN class=cb2&gt;static&lt;/SPAN&gt; &lt;SPAN class=cb2&gt;void&lt;/SPAN&gt; AddStructureChangedEventHandler(&lt;SPAN class=cb3&gt;AutomationElement&lt;/SPAN&gt; element, &lt;SPAN class=cb3&gt;TreeScope&lt;/SPAN&gt; scope, &lt;SPAN class=cb3&gt;StructureChangedEventHandler&lt;/SPAN&gt; eventHandler);&lt;/P&gt;&lt;/DIV&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The UIAutomation API is much more friendly to use, but some times it takes too long for the event to reach the handler. You should be very precise when setting the element and scope to subscribe the event to. You can find more information about this API and sample code on my previous post about &lt;A href="http://weblogs.asp.net/spano/archive/2007/09/07/wpf-accessibility.aspx" mce_href="http://weblogs.asp.net/spano/archive/2007/09/07/wpf-accessibility.aspx"&gt;WPF Accessibility&lt;/A&gt;.&lt;/P&gt;</description><pubDate>Tue, 15 Jan 2008 15:05:00 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/spano/ccf-listening-to-external-application-events</guid><category>CCF</category></item><item><title>Hosting a Window Form Control in a SharePoint WebPart</title><link>https://weblogs.asp.net:443/spano/hosting-a-window-form-control-in-a-sharepoint-webpart</link><description>&lt;P&gt;Some months ago I posted about &lt;A href="http://weblogs.asp.net/spano/archive/2007/09/19/hosting-a-windows-form-control-in-a-web-page.aspx" mce_href="http://weblogs.asp.net/spano/archive/2007/09/19/hosting-a-windows-form-control-in-a-web-page.aspx"&gt;Hosting a Windows Form Control in a web page&lt;/A&gt;. I explained there how we can run a WinForm control from Internet Explorer by hosting it in a web page using the &amp;lt;object&amp;gt; tag. Now suppose you want to use the same solution in a custom web part that is included in a Sharepoint site. I will describe here where the control library should be placed and how it can be referenced from the web part.&lt;/P&gt;
&lt;P&gt;When we develop a custom web part, we place its resources under the _wpresources web site, into a folder named &amp;lt;WebPartAssemblyName&amp;gt;/&amp;lt;WebPartAssemblyVersion&amp;gt;__&amp;lt;PublicKeyToken&amp;gt;. You can create there a subfolder (named "bin" por example) to place the win control assembly. This folder must have execute permissions set to Script Only (not Script and Executables as is the default under a SharePoint site). The picture bellow shows the resulting structure when placing the win form control assembly in a web part called MyCustomWebPart that is part of the MyCustomWebParts assembly: &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;IMG src="http://weblogs.asp.net/blogs/spano/sharepointWinControls.JPG" mce_src="https://aspblogs.blob.core.windows.net/media/spano/Media/sharepointWinControls.JPG"&gt; &lt;/P&gt;
&lt;P&gt;Once the control assembly is placed in the correct place, the web part can render the &amp;lt;object&amp;gt; tag within the RenderWebPart method:&lt;/P&gt;
&lt;P&gt;&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red0\green0\blue0;\red128\green128\blue128;\red0\green128\blue0;\red43\green145\blue175;\red163\green21\blue21;}??\fs20 \cf1 namespace\cf0  WorkbookCart\par ??\{\par ??    \cf4 ///\cf5  \cf4 &amp;lt;summary&amp;gt;\par ??\cf0     \cf4 ///\cf5  Web part que permite agregar al carrito, imprimir y exportar a Power Point la car\'e1tula u hoja Excel del sitio al que pertenece. \par ??\cf0     \cf4 ///\cf5  Deben setearse antes de ser usada las propiedades SheetTitle, WorkbookUrl y NamedItem. SheetTitle es obligatoria siempre. \par ??\cf0     \cf4 ///\cf5  Las dos \'faltimas son obligatorias si se trata de una hoja excel. Si se trata de una car\'e1tula se dejan en blanco.\par ??\cf0     \cf4 ///\cf5  Los botones dibujados en la web part permiten:\par ??\cf0     \cf4 ///\cf5  1- Agregar el sitio actual al carrito (se agrega a la lista del carrito un \'edtem con los valores de las properties seteadas a la web part el sitio actual.\par ??\cf0     \cf4 ///\cf5  2- Agregar el sitio actual y todos sus subsitios al carrito\par ??\cf0     \cf4 ///\cf5  3- Imprimir la hoja o car\'e1tula \par ??\cf0     \cf4 ///\cf5  4- Exportar a power point \par ??\cf0     \cf4 ///\cf5  \cf4 &amp;lt;/summary&amp;gt;\par ??\cf0     [\cf6 XmlRoot\cf0 (Namespace = \cf7 "WorkbookCart"\cf0 )]\par ??    \cf1 public\cf0  \cf1 class\cf0  \cf6 AddToCartWebPart\cf0  : \cf6 BaseCartWebPart\par ??\cf0     \{\par ??}
--&gt;&lt;/P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: courier new"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;namespace&lt;/SPAN&gt; MyCustomWebParts&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;{&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; [&lt;SPAN style="COLOR: #2b91af"&gt;XmlRoot&lt;/SPAN&gt;(Namespace = &lt;SPAN style="COLOR: #a31515"&gt;"MyCustomWebParts"&lt;/SPAN&gt;)]&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;class&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;MyCustomWebPart&lt;/SPAN&gt; : &lt;SPAN style="COLOR: #2b91af"&gt;WebPart&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp; {&lt;/P&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;\red163\green21\blue21;\red0\green128\blue0;}??\fs20         \cf3 protected\cf0  \cf3 override\cf0  \cf3 void\cf0  RenderWebPart(\cf4 HtmlTextWriter\cf0  output)\par ??        \{\par ??            EnsureChildControls();\par ??\par ??            \cf3 string\cf0  list = \cf4 String\cf0 .Format(\cf5 "\{0\}*\{1\}*\{2\}"\cf0 , _title, _workbookUrl, _namedItem);\par ??\par ??            output.Write(ReplaceTokens(GetCartScriptBlock(list)));\par ??            output.Write(ReplaceTokens(GetCartDefinitionBlock()));\par ??\par ??            \cf3 string\cf0  resourcePath = \cf4 SPWebPartManager\cf0 .GetClassResourcePath(\cf4 SPContext\cf0 .Current.Web, GetType());\par ??            output.Write( ReplaceTokens(\cf5 "&amp;lt;h1&amp;gt;Windows Form Control:&amp;lt;/h1&amp;gt;"\cf0  +\par ??                \cf5 "&amp;lt;object id='MyWinControl' classid='"\cf0  + resourcePath + \cf5 "/bin/WindowsControlLibrary1.dll#WindowsControlLibrary1.UserControl1'"\cf0  +\par ??                \cf5 "height='300' width='800' VIEWASTEXT&amp;gt;"\cf0  +\par ??                \cf5 "  &amp;lt;PARAM name='Prop1Str' value='blabla'  valuetype='data'&amp;gt;"\cf0  +\par ??                \cf5 "  &amp;lt;PARAM name='Prop2Int' value='2' valuetype='data'&amp;gt;"\cf0  +\par ??                \cf5 " &amp;lt;/object&amp;gt;"\cf0 ));\par ??\par ??\par ??  \cf6 //          SPWeb web = SPContext.Current.Web;\par ??\cf0   \cf6 //          string resourcePath = SPWebPartManager.GetClassResourcePath(web, GetType());\par ??\cf0   \cf6 //          output.Write(ReplaceTokens("&amp;lt;h1&amp;gt;Windows Form Control with param:&amp;lt;/h1&amp;gt;" +     \par ??\cf0   \cf6 //"&amp;lt;object id='MyWinControl' classid='"+resourcePath+"/bin/WindowsControlLibrary1.dll#WindowsControlLibrary1.UserControl1'"+            \par ??\cf0   \cf6 //        "height='300' width='800' VIEWASTEXT&amp;gt;"+\par ??\cf0   \cf6 //        "&amp;lt;PARAM name='Title' value='SOLE desde web part'  valuetype='data'&amp;gt;"+\par ??\cf0   \cf6 //        "&amp;lt;PARAM name='FontSize' value='0.2' valuetype='data'&amp;gt;"+\par ??\cf0   \cf6 //        "hola"+\par ??\cf0   \cf6 //        "&amp;lt;/object&amp;gt;"));\par ??\par ??\cf0             \cf3 base\cf0 .RenderWebPart(output);\par ??        \}\par ??}
--&gt;
&lt;STYLE type=text/css&gt;




.cf { font-family: courier new; font-size: 10pt; color: black; background: white; }
.cl { margin: 0px; }
.cb1 { color: blue; }
.cb2 { color: #2b91af; }
.cb3 { color: #a31515; }
.cb4 { color: green; }&lt;/STYLE&gt;
&lt;/P&gt;
&lt;DIV class=cf&gt;
&lt;P class=cl&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class=cb1&gt;protected&lt;/SPAN&gt; &lt;SPAN class=cb1&gt;override&lt;/SPAN&gt; &lt;SPAN class=cb1&gt;void&lt;/SPAN&gt; RenderWebPart(&lt;SPAN class=cb2&gt;HtmlTextWriter&lt;/SPAN&gt; output)&lt;/P&gt;
&lt;P class=cl&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P class=cl&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; EnsureChildControls();&lt;/P&gt;
&lt;P class=cl&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class=cb1&gt;string&lt;/SPAN&gt; resourcePath = &lt;SPAN class=cb2&gt;SPWebPartManager&lt;/SPAN&gt;.GetClassResourcePath(&lt;SPAN class=cb2&gt;SPContext&lt;/SPAN&gt;.Current.Web, GetType());&lt;/P&gt;
&lt;P class=cl&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;
&lt;P class=cl&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output.Write( ReplaceTokens(&lt;SPAN class=cb3&gt;"&amp;lt;h1&amp;gt;Windows Form Control:&amp;lt;/h1&amp;gt;"&lt;/SPAN&gt; +&lt;/P&gt;
&lt;P class=cl&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class=cb3&gt;"&amp;lt;object id='MyWinControl' classid='"&lt;/SPAN&gt; + resourcePath +&lt;SPAN class=cb3&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P class=cl&gt;&lt;STRONG&gt;&lt;SPAN class=cb3&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "/bin/WindowsControlLibrary1.dll#WindowsControlLibrary1.UserControl1'"&lt;/SPAN&gt; +&lt;/STRONG&gt;&lt;/P&gt;
&lt;P class=cl&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class=cb3&gt;"height='300' width='800' VIEWASTEXT&amp;gt;"&lt;/SPAN&gt; +&lt;/P&gt;
&lt;P class=cl&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class=cb3&gt;"&amp;nbsp; &amp;lt;PARAM name='Prop1Str' value='blabla'&amp;nbsp; valuetype='data'&amp;gt;"&lt;/SPAN&gt; +&lt;/P&gt;
&lt;P class=cl&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class=cb3&gt;"&amp;nbsp; &amp;lt;PARAM name='Prop2Int' value='2' valuetype='data'&amp;gt;"&lt;/SPAN&gt; +&lt;/P&gt;
&lt;P class=cl&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class=cb3&gt;" &amp;lt;/object&amp;gt;"&lt;/SPAN&gt;));&lt;/P&gt;
&lt;P class=cl mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=cl&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class=cb1&gt;base&lt;/SPAN&gt;.RenderWebPart(output);&lt;/P&gt;
&lt;P class=cl&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P class=cl&gt;&amp;nbsp; }&lt;/P&gt;
&lt;P class=cl&gt;} &lt;/P&gt;&lt;/DIV&gt;</description><pubDate>Fri, 07 Dec 2007 01:48:00 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/spano/hosting-a-window-form-control-in-a-sharepoint-webpart</guid><category>Sharepoint</category></item><item><title>CCF HAT - Making use of DDAs from Legacy Adapters</title><link>https://weblogs.asp.net:443/spano/ccf-hat-making-use-of-ddas-from-legacy-adapters</link><description>&lt;P&gt;Although Data Driven Adapters (DDAs) are mainly designed for Automation Adapters in HAT, we can make use of them from legacy adapters, too. Here's an example of an external VB application, which is configured to use a legacy application adapter and a WinDataDrivenAdapter with the corresponding bindings:&lt;/P&gt;
&lt;P&gt;&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red163\green21\blue21;\red255\green0\blue0;\red0\green0\blue0;}??\fs20 \cf1 &amp;lt;?\cf3 xml\cf1  \cf4 version\cf1 =\cf0 "\cf1 1.0\cf0 "\cf1  \cf4 encoding\cf1 =\cf0 "\cf1 utf-16\cf0 "\cf1 ?&amp;gt;\par ??&amp;lt;\cf3 initstring\cf1 &amp;gt;\par ??\tab &amp;lt;\cf3 interopAssembly\cf1 &amp;gt;\par ??\tab \tab &amp;lt;\cf3 URL\cf1 &amp;gt;\cf0 C:\\MyApp.exe\cf1 &amp;lt;/\cf3 URL\cf1 &amp;gt;\par ??\tab \tab &amp;lt;\cf3 WorkingDirectory\cf1 &amp;gt;\cf0 C:\\\cf1 &amp;lt;/\cf3 WorkingDirectory\cf1 &amp;gt;\par ??\tab \tab &amp;lt;\cf3 hostInside\cf1  /&amp;gt;\par ??\tab &amp;lt;/\cf3 interopAssembly\cf1 &amp;gt;\par ??\tab &amp;lt;\cf3 UseTopLevelWindow\cf1  \cf4 class\cf1 =\cf0 "\cf1 ThunderRT6Form\cf0 "\cf1  /&amp;gt;\par ??\tab &amp;lt;\cf3 adapter\cf1 &amp;gt;\par ??\tab \tab &amp;lt;\cf3 URL\cf1 &amp;gt;\cf0 C:\\MyApplicationAdapters.dll\cf1 &amp;lt;/\cf3 URL\cf1 &amp;gt;\par ??\tab \tab &amp;lt;\cf3 type\cf1 &amp;gt;\cf0 Microsoft.Ccf.QuickStarts.MyExtVBAppAdapter\cf1 &amp;lt;/\cf3 type\cf1 &amp;gt;\par ??\tab &amp;lt;/\cf3 adapter\cf1 &amp;gt;\par ??\tab &amp;lt;\cf3 DataDrivenAdapterBindings\cf1 &amp;gt;\par ??\tab \tab &amp;lt;\cf3 Type\cf1 &amp;gt;\cf0 Microsoft.Ccf.HostedApplicationToolkit.DataDrivenAdapter.WinDataDrivenAdapter, \par ??\tab \tab \tab   Microsoft.Ccf.HostedApplicationToolkit.DataDrivenAdapter\cf1 &amp;lt;/\cf3 Type\cf1 &amp;gt;\par ??\tab \tab &amp;lt;\cf3 Controls\cf1 &amp;gt;\par ??\tab \tab \tab &amp;lt;\cf3 AccControl\cf1  \cf4 name\cf1 =\cf0 "\cf1 button1\cf0 "\cf1 &amp;gt;\par ??\tab \tab \tab \tab &amp;lt;\cf3 Path\cf1 &amp;gt;\par ??\tab \tab \tab \tab \tab &amp;lt;\cf3 Next\cf1 &amp;gt;\cf0 OK\cf1 &amp;lt;/\cf3 Next\cf1 &amp;gt;\par ??\tab \tab \tab \tab &amp;lt;/\cf3 Path\cf1 &amp;gt;\par ??\tab \tab \tab &amp;lt;/\cf3 AccControl\cf1 &amp;gt;\par ??\tab \tab &amp;lt;/\cf3 Controls\cf1 &amp;gt;\par ??\tab &amp;lt;/\cf3 DataDrivenAdapterBindings\cf1 &amp;gt;\par ??\tab &amp;lt;\cf3 optimumSize\cf1  \cf4 x\cf1 =\cf0 "\cf1 800\cf0 "\cf1  \cf4 y\cf1 =\cf0 "\cf1 600\cf0 "\cf1  /&amp;gt;\par ??\tab &amp;lt;\cf3 minimumSize\cf1  \cf4 x\cf1 =\cf0 "\cf1 640\cf0 "\cf1  \cf4 y\cf1 =\cf0 "\cf1 480\cf0 "\cf1  /&amp;gt;\par ??&amp;lt;/\cf3 initstring\cf1 &amp;gt;}
--&gt;
&lt;STYLE type=text/css&gt;

.cf { font-family: courier new; font-size: 10pt; color: black; background: white; }
.cl { margin: 0px; }
.cb1 { color: blue; }
.cb2 { color: #a31515; }
.cb3 { color: red; }&lt;/STYLE&gt;
&lt;/P&gt;
&lt;DIV class=cf&gt;
&lt;P class=cl&gt;&lt;SPAN class=cb1&gt;&amp;lt;?&lt;/SPAN&gt;&lt;SPAN class=cb2&gt;xml&lt;/SPAN&gt;&lt;SPAN class=cb1&gt; &lt;/SPAN&gt;&lt;SPAN class=cb3&gt;version&lt;/SPAN&gt;&lt;SPAN class=cb1&gt;=&lt;/SPAN&gt;"&lt;SPAN class=cb1&gt;1.0&lt;/SPAN&gt;"&lt;SPAN class=cb1&gt; &lt;/SPAN&gt;&lt;SPAN class=cb3&gt;encoding&lt;/SPAN&gt;&lt;SPAN class=cb1&gt;=&lt;/SPAN&gt;"&lt;SPAN class=cb1&gt;utf-16&lt;/SPAN&gt;"&lt;SPAN class=cb1&gt;?&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=cl&gt;&lt;SPAN class=cb1&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=cb2&gt;initstring&lt;/SPAN&gt;&lt;SPAN class=cb1&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=cl&gt;&lt;SPAN class=cb1&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/SPAN&gt;&lt;SPAN class=cb2&gt;interopAssembly&lt;/SPAN&gt;&lt;SPAN class=cb1&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=cl&gt;&lt;SPAN class=cb1&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/SPAN&gt;&lt;SPAN class=cb2&gt;URL&lt;/SPAN&gt;&lt;SPAN class=cb1&gt;&amp;gt;&lt;/SPAN&gt;C:\MyApp.exe&lt;SPAN class=cb1&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=cb2&gt;URL&lt;/SPAN&gt;&lt;SPAN class=cb1&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=cl&gt;&lt;SPAN class=cb1&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/SPAN&gt;&lt;SPAN class=cb2&gt;WorkingDirectory&lt;/SPAN&gt;&lt;SPAN class=cb1&gt;&amp;gt;&lt;/SPAN&gt;C:\&lt;SPAN class=cb1&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=cb2&gt;WorkingDirectory&lt;/SPAN&gt;&lt;SPAN class=cb1&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=cl&gt;&lt;SPAN class=cb1&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/SPAN&gt;&lt;SPAN class=cb2&gt;hostInside&lt;/SPAN&gt;&lt;SPAN class=cb1&gt; /&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=cl&gt;&lt;SPAN class=cb1&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=cb2&gt;interopAssembly&lt;/SPAN&gt;&lt;SPAN class=cb1&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=cl&gt;&lt;STRONG&gt;&lt;SPAN class=cb1&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/SPAN&gt;&lt;SPAN class=cb2&gt;UseTopLevelWindow&lt;/SPAN&gt;&lt;SPAN class=cb1&gt; &lt;/SPAN&gt;&lt;SPAN class=cb3&gt;class&lt;/SPAN&gt;&lt;SPAN class=cb1&gt;=&lt;/SPAN&gt;"&lt;SPAN class=cb1&gt;ThunderRT6Form&lt;/SPAN&gt;"&lt;SPAN class=cb1&gt; /&amp;gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P class=cl&gt;&lt;SPAN class=cb1&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/SPAN&gt;&lt;SPAN class=cb2&gt;adapter&lt;/SPAN&gt;&lt;SPAN class=cb1&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=cl&gt;&lt;SPAN class=cb1&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/SPAN&gt;&lt;SPAN class=cb2&gt;URL&lt;/SPAN&gt;&lt;SPAN class=cb1&gt;&amp;gt;&lt;/SPAN&gt;C:\MyApplicationAdapters.dll&lt;SPAN class=cb1&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=cb2&gt;URL&lt;/SPAN&gt;&lt;SPAN class=cb1&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=cl&gt;&lt;SPAN class=cb1&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/SPAN&gt;&lt;SPAN class=cb2&gt;type&lt;/SPAN&gt;&lt;SPAN class=cb1&gt;&amp;gt;&lt;/SPAN&gt;Microsoft.Ccf.QuickStarts.MyExtVBAppAdapter&lt;SPAN class=cb1&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=cb2&gt;type&lt;/SPAN&gt;&lt;SPAN class=cb1&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=cl&gt;&lt;SPAN class=cb1&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=cb2&gt;adapter&lt;/SPAN&gt;&lt;SPAN class=cb1&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=cl&gt;&lt;SPAN class=cb1&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/SPAN&gt;&lt;SPAN class=cb2&gt;DataDrivenAdapterBindings&lt;/SPAN&gt;&lt;SPAN class=cb1&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=cl&gt;&lt;SPAN class=cb1&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/SPAN&gt;&lt;SPAN class=cb2&gt;Type&lt;/SPAN&gt;&lt;SPAN class=cb1&gt;&amp;gt;&lt;/SPAN&gt;Microsoft.Ccf.HostedApplicationToolkit.DataDrivenAdapter.WinDataDrivenAdapter, &lt;/P&gt;
&lt;P class=cl&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Microsoft.Ccf.HostedApplicationToolkit.DataDrivenAdapter&lt;SPAN class=cb1&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=cb2&gt;Type&lt;/SPAN&gt;&lt;SPAN class=cb1&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=cl&gt;&lt;SPAN class=cb1&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/SPAN&gt;&lt;SPAN class=cb2&gt;Controls&lt;/SPAN&gt;&lt;SPAN class=cb1&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=cl&gt;&lt;SPAN class=cb1&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/SPAN&gt;&lt;SPAN class=cb2&gt;AccControl&lt;/SPAN&gt;&lt;SPAN class=cb1&gt; &lt;/SPAN&gt;&lt;SPAN class=cb3&gt;name&lt;/SPAN&gt;&lt;SPAN class=cb1&gt;=&lt;/SPAN&gt;"&lt;SPAN class=cb1&gt;button1&lt;/SPAN&gt;"&lt;SPAN class=cb1&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=cl&gt;&lt;SPAN class=cb1&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/SPAN&gt;&lt;SPAN class=cb2&gt;Path&lt;/SPAN&gt;&lt;SPAN class=cb1&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=cl&gt;&lt;SPAN class=cb1&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/SPAN&gt;&lt;SPAN class=cb2&gt;Next&lt;/SPAN&gt;&lt;SPAN class=cb1&gt;&amp;gt;&lt;/SPAN&gt;OK&lt;SPAN class=cb1&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=cb2&gt;Next&lt;/SPAN&gt;&lt;SPAN class=cb1&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=cl&gt;&lt;SPAN class=cb1&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=cb2&gt;Path&lt;/SPAN&gt;&lt;SPAN class=cb1&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=cl&gt;&lt;SPAN class=cb1&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=cb2&gt;AccControl&lt;/SPAN&gt;&lt;SPAN class=cb1&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=cl&gt;&lt;SPAN class=cb1&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=cb2&gt;Controls&lt;/SPAN&gt;&lt;SPAN class=cb1&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=cl&gt;&lt;SPAN class=cb1&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=cb2&gt;DataDrivenAdapterBindings&lt;/SPAN&gt;&lt;SPAN class=cb1&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=cl&gt;&lt;SPAN class=cb1&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/SPAN&gt;&lt;SPAN class=cb2&gt;optimumSize&lt;/SPAN&gt;&lt;SPAN class=cb1&gt; &lt;/SPAN&gt;&lt;SPAN class=cb3&gt;x&lt;/SPAN&gt;&lt;SPAN class=cb1&gt;=&lt;/SPAN&gt;"&lt;SPAN class=cb1&gt;800&lt;/SPAN&gt;"&lt;SPAN class=cb1&gt; &lt;/SPAN&gt;&lt;SPAN class=cb3&gt;y&lt;/SPAN&gt;&lt;SPAN class=cb1&gt;=&lt;/SPAN&gt;"&lt;SPAN class=cb1&gt;600&lt;/SPAN&gt;"&lt;SPAN class=cb1&gt; /&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=cl&gt;&lt;SPAN class=cb1&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/SPAN&gt;&lt;SPAN class=cb2&gt;minimumSize&lt;/SPAN&gt;&lt;SPAN class=cb1&gt; &lt;/SPAN&gt;&lt;SPAN class=cb3&gt;x&lt;/SPAN&gt;&lt;SPAN class=cb1&gt;=&lt;/SPAN&gt;"&lt;SPAN class=cb1&gt;640&lt;/SPAN&gt;"&lt;SPAN class=cb1&gt; &lt;/SPAN&gt;&lt;SPAN class=cb3&gt;y&lt;/SPAN&gt;&lt;SPAN class=cb1&gt;=&lt;/SPAN&gt;"&lt;SPAN class=cb1&gt;480&lt;/SPAN&gt;"&lt;SPAN class=cb1&gt; /&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=cl&gt;&lt;SPAN class=cb1&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=cb2&gt;initstring&lt;/SPAN&gt;&lt;SPAN class=cb1&gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One thing to take into account is that, if the application uses an alternative top level window, the DDA must be instantiated with that top level window instead of the process MainWindowHandle. The picture shows how the alternate top level window configuration is seen in the Admin Console:&lt;/P&gt;
&lt;P&gt;&lt;IMG id=id src="http://weblogs.asp.net/blogs/spano/hat_useTopLevelWnd.JPG" mce_src="https://aspblogs.blob.core.windows.net/media/spano/Media/hat_useTopLevelWnd.JPG"&gt; &lt;/P&gt;
&lt;P&gt;And here is the code of the legacy adapter making use of the data driven adapter to automate the hosted application's UI:&lt;/P&gt;
&lt;P&gt;&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red0\green0\blue0;\red0\green128\blue0;\red43\green145\blue175;\red163\green21\blue21;}??\fs20 \cf1 using\cf0  System;\par ??\cf1 using\cf0  Microsoft.Ccf.Csr;\par ??\cf1 using\cf0  Microsoft.Ccf.HostedApplicationToolkit.DataDrivenAdapter;\par ??\par ??\cf1 namespace\cf0  Microsoft.Ccf.BancoGalicia.ApplicationAdapters\par ??\{\par ??    \cf1 public\cf0  \cf1 class\cf0  MyExtVBAppAdapter : ApplicationAdapter\par ??    \{\par ??        \cf1 protected\cf0  DataDrivenAdapterBase _dda;\par ??\par ??        \cf1 public\cf0  \cf1 override\cf0  \cf1 bool\cf0  Initialize()\par ??        \{\par ??            \cf4 //IntPtr topLevelWnd = Process.MainWindowHandle;//this won't work for a VB app \par ??\cf0             \cf5 IntPtr\cf0  topLevelWnd = GetTopLevelWndHandle();\par ??            \cf4 //Initialize Data Driven Adapter with proper top level window handle\par ??\cf0             _dda = DataDrivenAdapterBase.CreateInstance(ApplicationInitString, topLevelWnd);\par ??            \cf1 return\cf0  _dda != \cf1 null\cf0 ;\par ??        \}\par ??\par ??        \cf1 public\cf0  \cf1 override\cf0  \cf1 bool\cf0  DoAction(Action action, RequestActionEventArgs args)\par ??        \{\par ??            \cf1 switch\cf0  (args.Action)\par ??            \{\par ??                \cf1 case\cf0  \cf6 "DefaultAction"\cf0 :\par ??                    \cf1 break\cf0 ;\par ??                \cf1 case\cf0  \cf6 "PressButton"\cf0 :\par ??                    PressButton();\par ??                    \cf1 break\cf0 ;\par ??            \}\par ??            \cf1 return\cf0  \cf1 base\cf0 .DoAction(action, args);\par ??\par ??        \}\par ??\par ??        \cf1 private\cf0  \cf1 void\cf0  PressButton()\par ??        \{\par ??            \cf1 if\cf0  (_dda.FindControl(\cf6 "button1"\cf0 ))\par ??            \{\par ??                _dda.ExecuteControlAction(\cf6 "button1"\cf0 );\par ??            \}\par ??        \}\par ??\par ??        \cf4 //Find the top level window of the VB application (for example of class "ThunderRT6Form")\par ??\cf0         \cf1 private\cf0  \cf5 IntPtr\cf0  GetTopLevelWndHandle()\par ??        \{\par ??            \cf5 IntPtr\cf0  agentDesktopPtr = Win32API.FindWindow(\cf1 null\cf0 , \cf6 "Agent Desktio"\cf0 );\par ??            \cf1 if\cf0  (agentDesktopPtr != \cf5 IntPtr\cf0 .Zero)\par ??            \{\par ??                \cf5 IntPtr\cf0  tabWindowHandle = Win32API.FindWindowByText(agentDesktopPtr, \cf6 "MyApp"\cf0 );\par ??                \cf1 if\cf0  (tabWindowHandle != \cf5 IntPtr\cf0 .Zero)\par ??                \{\par ??                    \cf1 return\cf0  Win32API.FindWindowByText(tabWindowHandle, \cf6 "MyAppTopLevelWndCaption"\cf0 );\par ??                \}\par ??            \}\par ??            \cf1 return\cf0  \cf5 IntPtr\cf0 .Zero;\par ??        \}\par ??\par ??    \}\par ??\}\par ??}
--&gt;&lt;/P&gt;
&lt;DIV style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: courier new"&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;using&lt;/SPAN&gt; System;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;using&lt;/SPAN&gt; Microsoft.Ccf.Csr;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;using&lt;/SPAN&gt; Microsoft.Ccf.HostedApplicationToolkit.DataDrivenAdapter;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;namespace&lt;/SPAN&gt; Microsoft.Ccf.BancoGalicia.ApplicationAdapters&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;{&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;class&lt;/SPAN&gt; MyExtVBAppAdapter : ApplicationAdapter&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;protected&lt;/SPAN&gt; DataDrivenAdapterBase _dda;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;override&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;bool&lt;/SPAN&gt; Initialize()&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;//IntPtr topLevelWnd = Process.MainWindowHandle;//this won't work for a VB app &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #2b91af"&gt;IntPtr&lt;/SPAN&gt; topLevelWnd = GetTopLevelWndHandle();&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;//Initialize Data Driven Adapter with proper top level window handle&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _dda = DataDrivenAdapterBase.CreateInstance(ApplicationInitString, topLevelWnd);&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; _dda != &lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;override&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;bool&lt;/SPAN&gt; DoAction(Action action, RequestActionEventArgs args)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;switch&lt;/SPAN&gt; (args.Action)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;case&lt;/SPAN&gt; &lt;SPAN style="COLOR: #a31515"&gt;"DefaultAction"&lt;/SPAN&gt;:&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;break&lt;/SPAN&gt;;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;case&lt;/SPAN&gt; &lt;SPAN style="COLOR: #a31515"&gt;"PressButton"&lt;/SPAN&gt;:&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PressButton();&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;break&lt;/SPAN&gt;;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;base&lt;/SPAN&gt;.DoAction(action, args);&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;void&lt;/SPAN&gt; PressButton()&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; (_dda.FindControl(&lt;SPAN style="COLOR: #a31515"&gt;"button1"&lt;/SPAN&gt;))&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _dda.ExecuteControlAction(&lt;SPAN style="COLOR: #a31515"&gt;"button1"&lt;/SPAN&gt;);&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;//Find the top level window of the VB application (for example of class "ThunderRT6Form")&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;private&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;IntPtr&lt;/SPAN&gt; GetTopLevelWndHandle()&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #2b91af"&gt;IntPtr&lt;/SPAN&gt; agentDesktopPtr = Win32API.FindWindow(&lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"Agent Desktio"&lt;/SPAN&gt;);&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; (agentDesktopPtr != &lt;SPAN style="COLOR: #2b91af"&gt;IntPtr&lt;/SPAN&gt;.Zero)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #2b91af"&gt;IntPtr&lt;/SPAN&gt; tabWindowHandle = Win32API.FindWindowByText(agentDesktopPtr, &lt;SPAN style="COLOR: #a31515"&gt;"MyApp"&lt;/SPAN&gt;);&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; (tabWindowHandle != &lt;SPAN style="COLOR: #2b91af"&gt;IntPtr&lt;/SPAN&gt;.Zero)&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; Win32API.FindWindowByText(tabWindowHandle, &lt;SPAN style="COLOR: #a31515"&gt;"MyAppTopLevelWndCaption"&lt;/SPAN&gt;);&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;IntPtr&lt;/SPAN&gt;.Zero;&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P style="MARGIN: 0px"&gt;}&amp;nbsp; &lt;/P&gt;&lt;/DIV&gt;</description><pubDate>Wed, 31 Oct 2007 01:34:00 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/spano/ccf-hat-making-use-of-ddas-from-legacy-adapters</guid><category>CCF</category></item><item><title>CCF 2008 Hosted Application Toolkit</title><link>https://weblogs.asp.net:443/spano/ccf-2008-hosted-application-toolkit</link><description>&lt;p&gt;The Hosted Application Toolkit (HAT) is a new component of CCF 2.6 (2008) that facilitates the task of automating the UI of the hosted applications. It consists of two main parts: the Data Driven Adapters (DDA) and the Automations (WF workflows) that automates the hosted application using the DDAs.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;u&gt;&lt;/u&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;u&gt;Data Driven Adapters&lt;/u&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;DDAs must inherit from DataDrivenAdapterBase in Microsoft.Ccf.HostedApplicationToolkit. CCF supports two implementations out of the box: WinDataDrivenAdapter and WebDataDrivenAdapter. We can inherit from any of the three to extend the DDA as necessary. The methods the DDAs expose to manipulate the hosted application UI are ExecuteControlAction, FindControl, GetControlValue and SetControlValue. These methods take a friendly name as parameter and lets the application adapters interact with the hosted application UI abstracting from the details of how to obtain the control from that friendly name. The mapping between the controls' friendly names and the directions for the DDA to finding them is called Data Driven Adapter Binding and is part of the hosted app initialization string:&lt;/p&gt;  &lt;p&gt;&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red163\green21\blue21;\red0\green0\blue0;\red255\green0\blue0;}??\fs20 \cf1 &amp;lt;\cf3 DataDrivenAdapterBindings\cf1 &amp;gt;\par ??\tab &amp;lt;\cf3 Type\cf1 &amp;gt;\cf0 Microsoft.Ccf.HostedApplicationToolkit.DataDrivenAdapter.WinDataDrivenAdapter\cf1 &amp;lt;/\cf3 Type\cf1 &amp;gt;\par ??\tab &amp;lt;\cf3 Controls\cf1 &amp;gt;\par ??\tab \tab &amp;lt;\cf3 AccControl\cf1  \cf5 name\cf1 =\cf0 "\cf1 okButton\cf0 "\cf1 &amp;gt;\par ??\tab \tab \tab &amp;lt;\cf3 Path\cf1 &amp;gt;\par ??\tab \tab \tab \tab &amp;lt;\cf3 FindWindow\cf1 &amp;gt;\par ??\tab \tab \tab \tab \tab &amp;lt;\cf3 ControlID\cf1 &amp;gt;\cf0 15\cf1 &amp;lt;/\cf3 ControlID\cf1 &amp;gt;\par ??\tab \tab \tab \tab &amp;lt;/\cf3 FindWindow\cf1 &amp;gt;\par ??\tab \tab \tab &amp;lt;/\cf3 Path\cf1 &amp;gt;\par ??\tab \tab &amp;lt;/\cf3 AccControl\cf1 &amp;gt;\par ??\tab \tab &amp;lt;\cf3 AccControl\cf1  \cf5 name\cf1 =\cf0 "\cf1 cancelButton\cf0 "\cf1 &amp;gt;\par ??\tab \tab \tab &amp;lt;\cf3 Path\cf1 &amp;gt;\par ??\tab \tab \tab \tab &amp;lt;\cf3 FindWindow\cf1 &amp;gt;\par ??\tab \tab \tab \tab \tab &amp;lt;\cf3 ControlID\cf1 &amp;gt;\cf0 15\cf1 &amp;lt;/\cf3 ControlID\cf1 &amp;gt;\par ??\tab \tab \tab \tab &amp;lt;/\cf3 FindWindow\cf1 &amp;gt;\par ??\tab \tab \tab &amp;lt;/\cf3 Path\cf1 &amp;gt;\par ??\tab \tab &amp;lt;/\cf3 AccControl\cf1 &amp;gt;\par ??\tab &amp;lt;/\cf3 Controls\cf1 &amp;gt;\par ??&amp;lt;/\cf3 DataDrivenAdapterBindings\cf1 &amp;gt;\par ??}
--&gt;&lt;/p&gt;  &lt;div style="background: white none repeat scroll 0% 50%; font-size: 10pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; color: black; font-family: courier new;"&gt;   &lt;p style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;DataDrivenAdapterBindings&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;Type&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;Microsoft.Ccf.HostedApplicationToolkit.DataDrivenAdapter.WinDataDrivenAdapter&lt;span style="color: blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;Type&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;Controls&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;AccControl&lt;/span&gt;&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;name&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;okButton&lt;/span&gt;"&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;Path&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;FindWindow&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;ControlID&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;15&lt;span style="color: blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;ControlID&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;FindWindow&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;Path&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;AccControl&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;AccControl&lt;/span&gt;&lt;span style="color: blue;"&gt; &lt;/span&gt;&lt;span style="color: red;"&gt;name&lt;/span&gt;&lt;span style="color: blue;"&gt;=&lt;/span&gt;"&lt;span style="color: blue;"&gt;cancelButton&lt;/span&gt;"&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;Path&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;FindWindow&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;ControlID&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;15&lt;span style="color: blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;ControlID&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;FindWindow&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;Path&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;AccControl&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;Controls&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px;"&gt;&lt;span style="color: blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;DataDrivenAdapterBindings&lt;/span&gt;&lt;span style="color: blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt; &lt;/div&gt;  &lt;p&gt;&amp;nbsp;&lt;/p&gt;  &lt;p&gt;&lt;i&gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;&lt;i&gt;Note: It is a known issue that the initialization string of a hosted application is limited to 3902 characters. This may result a problem if several controls must be listed.&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;Although DDAs can be used from any custom adapter (and even outside CCF), they were mainly thought to support Automations in HAT. &lt;/p&gt;  &lt;p&gt;&amp;nbsp;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;u&gt;Automations&lt;/u&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;In previous versions of CCF we could choose to use an Application Adapter to implement the actions' logic. In version 2.6 we can choose between Automation Adapter, Legacy Adapter, or no adapter at all. The Legacy Adapter is the Application Adapter from the previous versions. We can implement our own Legacy Adapter inheriting from the [Web]ApplicationAdapter class. The Automation Adapter is the adapter that makes use of the new Workflow Foundation (WF) feature. The AutomationAdapter implements the IAutomationAdapter interface. However, if we choose AutomationAdapter in the hosted app configuration in the AdminConsole, we can't choose our own implementation of IAutomationAdapter.&lt;/p&gt;  &lt;p&gt;&lt;img src="http://weblogs.asp.net/blogs/spano/hat_adapterConfig.jpg" id="id" mce_src="https://aspblogs.blob.core.windows.net/media/spano/Media/hat_adapterConfig.jpg"&gt; &lt;/p&gt;  &lt;p&gt;If a hosted application is configured to use the AutomationAdapter, we can specify a WF workflow to implement an action's logic. Workflows in HAT are called Automations. &lt;/p&gt;  &lt;p&gt;&lt;img src="http://weblogs.asp.net/blogs/spano/hat_actionConfig.JPG" id="id" mce_src="https://aspblogs.blob.core.windows.net/media/spano/Media/hat_actionConfig.JPG"&gt; &lt;/p&gt;  &lt;p&gt;In order to orchestrate an action automation, a set of WF Activities are provided by CCF that interact with the DDAs to access the UI controls. There are activities for calling an action in a hosted application, setting or getting a control's value, accessing the context, register for an application event, etc. &lt;/p&gt;  &lt;p&gt;&lt;img src="http://weblogs.asp.net/blogs/spano/hatCCFActivities.JPG" id="id" mce_src="https://aspblogs.blob.core.windows.net/media/spano/Media/hatCCFActivities.JPG"&gt; &lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;u&gt;All together&lt;/u&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;The connection between the Automations and the DDAs is achieved by the AutomationBridgeService, which is in turn connected to the AutomationAdapter. As the bridge service is added to the WF runtime, it is accessible from the CCF WF activities. We can extend the set of activities and make use of this server, too.&lt;/p&gt;  &lt;p&gt;The following diagram depicts the relationship between the components mentioned above:&lt;/p&gt;  &lt;p&gt;&amp;nbsp;&lt;/p&gt;  &lt;p&gt;&amp;nbsp;&lt;img src="http://weblogs.asp.net/blogs/spano/HAT_uml2.jpg" id="id" mce_src="https://aspblogs.blob.core.windows.net/media/spano/Media/HAT_uml2.jpg"&gt; &lt;/p&gt;  &lt;p&gt;&amp;nbsp;&lt;/p&gt;  &lt;p&gt;More detailed documentation can be found in chapter 9 of the CCF 2008 Development Guide.&lt;/p&gt;</description><pubDate>Fri, 26 Oct 2007 03:40:00 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/spano/ccf-2008-hosted-application-toolkit</guid><category>CCF</category></item><item><title>Silverlight article published this month</title><link>https://weblogs.asp.net:443/spano/silverlight-article-published-this-month</link><description>&lt;P align=left&gt;My colleagues &lt;A href="http://weblogs.asp.net/arielneisen" mce_href="http://weblogs.asp.net/arielneisen"&gt;Ariel Neisen&lt;/A&gt;, Federico García, &lt;A href="http://weblogs.shockbyte.com.ar/rodolfof" mce_href="http://weblogs.shockbyte.com.ar/rodolfof"&gt;Rodolfo Finochietti&lt;/A&gt; and I wrote the cover article of the &lt;A href="http://www.redusers.com/noticias/code-42" mce_href="http://www.redusers.com/noticias/code-42"&gt;#42 edition of the .Code Magazine&lt;/A&gt; (in Spanish) about &lt;STRONG&gt;Silverlight&lt;/STRONG&gt;. The article talks about this new technology's fundamentals, architecture, programming tools, advanced features, code samples and a lot more. &lt;/P&gt;
&lt;P align=center&gt;&lt;IMG id=id src="https://aspblogs.blob.core.windows.net/media/spano/Media/tapa-code-42.gif"&gt; &lt;/P&gt;
&lt;P align=left mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;</description><pubDate>Mon, 08 Oct 2007 02:23:00 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/spano/silverlight-article-published-this-month</guid></item><item><title>Choosing the right WCF binding</title><link>https://weblogs.asp.net:443/spano/choosing-the-right-wcf-binding</link><description>&lt;P&gt;A WCF binding is the endpoint component that defines &lt;EM&gt;how&lt;/EM&gt; the client needs to communicate with the service. It groups settings such as underlying transport protocol, security requirements, and message encoding.&lt;/P&gt;
&lt;P&gt;WCF provides nine built-in bindings: &lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;&lt;STRONG&gt;BasicHttpBinding&lt;/STRONG&gt;: Basic web service communication. Exposes WCF services as legacy ASMX web services. Used for interoperability. No security by default.&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;WSHttpBinding&lt;/STRONG&gt;: Web services with WS-* support. Supports transactions and reliable messaging.&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;WSDualHttpBinding&lt;/STRONG&gt;: Web services with duplex contract and transaction support.&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;WSFederationHttpBinding&lt;/STRONG&gt;: Web services with federated security. Supports transactions.&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;MsmqIntegrationBinding&lt;/STRONG&gt;: Communication directly with MSMQ applications. Supports transactions.&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;NetMsmqBinding&lt;/STRONG&gt;: Communication between WCF applications by using queuing. Supports transactions.&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;NetNamedPipeBinding&lt;/STRONG&gt;: Communication between WCF applications on same computer. Supports duplex contracts and transactions.&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;NetPeerTcpBinding&lt;/STRONG&gt;: Communication between computers across peer-to-peer services. Supports duplex contracts.&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;NetTcpBinding&lt;/STRONG&gt;: Communication between WCF applications across computers. Supports duplex contracts and transactions.&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;Although most bindings will work on scenarios they are not designed for, it's a good practice to choose the right binding for a given endpoint. In chapter one of the "&lt;A href="http://safari.oreilly.com/0596526997" mce_href="http://safari.oreilly.com/0596526997"&gt;Programming WCF Services&lt;/A&gt;" book, Juval Lowy provides a very useful decision-activity diagram for choosing the right binding:&lt;/P&gt;
&lt;P&gt;&lt;IMG id=id src="http://weblogs.asp.net/blogs/spano/WCFBindings.JPG" mce_src="https://aspblogs.blob.core.windows.net/media/spano/Media/WCFBindings.JPG"&gt; &lt;/P&gt;
&lt;P&gt;&lt;EM&gt;"The first question you should ask yourself is whether your service needs to interact with non-WCF clients. If the answer is yes, and if the client is a legacy MSMQ client, choose the &lt;STRONG&gt;MsmqIntegrationBinding&lt;/STRONG&gt; that enables your service to interoperate over MSMQ with such a client. If you need to interoperate with a non-WCF client and that client expects basic web service protocol (ASMX web services), choose the &lt;STRONG&gt;BasicHttpBinding&lt;/STRONG&gt;, which exposes your WCF service to the outside world as if it were an ASMX web service (that is, a WSI-basic profile). The downside is that you cannot take advantage of most of the modern WS-* protocols. However, if the non-WCF client can understand these standards, choose one of the WS bindings, such as &lt;STRONG&gt;WSHttpBinding&lt;/STRONG&gt;, &lt;STRONG&gt;WSFederationHttpBinding&lt;/STRONG&gt;, or &lt;STRONG&gt;WSDualHttpBinding&lt;/STRONG&gt;. If you can assume that the client is a WCF client, yet it requires offline or disconnected interaction, choose the &lt;STRONG&gt;NetMsmqBinding &lt;/STRONG&gt;that uses MSMQ for transporting the messages. If the client requires connected communication, but could be calling across machine boundaries, choose the &lt;STRONG&gt;NetTcpBinding &lt;/STRONG&gt;that communicates over TCP. If the client is on the same machine as the service, choose the &lt;STRONG&gt;NetNamedPipeBinding &lt;/STRONG&gt;that uses named pipes to maximize performance. You may fine-tune binding selections based on additional criteria such as the need for callbacks (&lt;STRONG&gt;WSDualHttpBinding&lt;/STRONG&gt;)&lt;/EM&gt;&lt;A&gt;&lt;/A&gt;&lt;EM&gt; or federated security (&lt;STRONG&gt;WSFederationHttpBinding&lt;/STRONG&gt;)."&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;You&amp;nbsp;can download the book's &lt;A class="" href="http://www.oreilly.com/catalog/9780596526993/chapter/index.html" mce_href="http://www.oreilly.com/catalog/9780596526993/chapter/index.html"&gt;sample chapter&lt;/A&gt; to read more on this subject.&amp;nbsp;You&amp;nbsp;would also&amp;nbsp;find the diagram&amp;nbsp;in&amp;nbsp;Juval's article&amp;nbsp;&lt;A class="" href="http://www.code-magazine.com/article.aspx?quickid=0605051&amp;amp;page=3" mce_href="http://www.code-magazine.com/article.aspx?quickid=0605051&amp;amp;page=3"&gt;WCF Essentials - A Developer's Primer&lt;/A&gt;&amp;nbsp;on the&amp;nbsp;CoDe Magazine.&amp;nbsp;&lt;SPAN id=article_content&gt;&lt;FONT face=Verdana&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;</description><pubDate>Tue, 02 Oct 2007 02:43:00 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/spano/choosing-the-right-wcf-binding</guid><category>WCF</category></item></channel></rss>