<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Tomasz Rabiński | zavaz Blog</title>
	
	<link>http://tomaszrabinski.pl</link>
	<description>C# SharePoint VSTO</description>
	<lastBuildDate>Mon, 27 Feb 2012 08:01:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/TomaszRabinskiZavazBlog" /><feedburner:info uri="tomaszrabinskizavazblog" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Enable or disable custom ribbon button in SharePoint 2010</title>
		<link>http://feedproxy.google.com/~r/TomaszRabinskiZavazBlog/~3/x-flyvRMhGE/</link>
		<comments>http://tomaszrabinski.pl/wordpress/2012/02/25/enable-or-disable-custom-ribbon-button-in-sharepoint-2010/#comments</comments>
		<pubDate>Sat, 25 Feb 2012 15:30:56 +0000</pubDate>
		<dc:creator>zavaz</dc:creator>
				<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[SharePoint 2010]]></category>
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://tomaszrabinski.pl/?p=584</guid>
		<description><![CDATA[My prevoius posts(here and here) described how to create a custom ribbon action and how to retrieve selected list items in SharePoint 2010. Right now I&#8217;ll show You one more thing that can be usefull while creating Your own ribbon buttons &#8211; how to enable or disable ribbon button using defined by You conditions. &#8220;EnabledScript&#8221; [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft" style="margin-right: 10px; margin-bottom: 5px;" title="On Off" src="http://farm6.staticflickr.com/5294/5516261029_bf210afac8_m.jpg" alt="http://www.flickr.com/photos/notthe1s/" width="124" height="124" />My prevoius posts(<a title="HERE" href="http://tomaszrabinski.pl/wordpress/2012/02/25/sharepoint-2010-custom-ribbon-button/" target="_blank">here</a> and <a title="HERE" href="http://tomaszrabinski.pl/wordpress/2012/02/25/get-selected-list-items-sharepoint-2010" target="_blank">here</a>) described how to create a custom ribbon action and how to retrieve selected list items in SharePoint 2010. Right now I&#8217;ll show You one more thing that can be usefull while creating Your own ribbon buttons &#8211; how to enable or disable ribbon button using defined by You conditions.<span id="more-584"></span></p>
<p>&#8220;EnabledScript&#8221; is a property of CommandUIHandler. It allows You to set if the ribbon button should be enabled(available to click for the user) or disabled(greyed out). To set this property dynamically You can use the script shown below:</p>
<pre class="brush: jscript; title: ; notranslate">

var EnableDisable = function() {
 this.clientContext = SP.ClientContext.get_current();
 this.selectedItems = SP.ListOperation.Selection.getSelectedItems(this.clientContext);
 var ci = CountDictionary(selectedItems);
 return (ci &gt; 0);
 };
 EnableDisable();
</pre>
<p>In the script I check if user has selected one or more list items. If yes, then method returns true, otherwise false.</p>
<p>Full command should be placed in the elements.xml and should look like this:</p>
<pre class="brush: xml; title: ; notranslate">

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?&gt;
&lt;Elements xmlns=&quot;http://schemas.microsoft.com/sharepoint/&quot;&gt;

&lt;CustomAction

Id=&quot;CAAlertRibbonButton&quot;
RegistrationId=&quot;100&quot;
RegistrationType=&quot;List&quot;
Location=&quot;CommandUI.Ribbon&quot;
Sequence=&quot;5&quot;
Title=&quot;Alert Ribbon Button&quot;&gt;

&lt;CommandUIExtension&gt;
&lt;CommandUIDefinitions&gt;
&lt;CommandUIDefinition Location=&quot;Ribbon.List.Settings.Controls._children&quot;&gt;
&lt;Button
Id=&quot;AlertRibbonButtonId&quot;
Alt=&quot;Alert Ribbon Button&quot;
Sequence=&quot;5&quot;
Command=&quot;CMDAlertRibbonButton&quot;
Image32by32=&quot;/_layouts/images/menulistsettings.gif&quot;
Image16by16=&quot;/_layouts/images/itdcl.gif&quot;
LabelText=&quot;Alert Ribbon Button&quot;
TemplateAlias=&quot;o1&quot; /&gt;
&lt;/CommandUIDefinition&gt;
&lt;/CommandUIDefinitions&gt;

&lt;CommandUIHandlers&gt;
&lt;CommandUIHandler
Command=&quot;CMDAlertRibbonButton&quot;
EnabledScript=&quot;javascript: var EnableDisable = function() {
 this.clientContext = SP.ClientContext.get_current();
 this.selectedItems = SP.ListOperation.Selection.getSelectedItems(this.clientContext);
 var ci = CountDictionary(selectedItems);
 return (ci &gt; 0);
 };
 EnableDisable();&quot;
CommandAction=&quot;javascript: alert('My Command!');&quot; /&gt;
&lt;/CommandUIHandlers&gt;

&lt;/CommandUIExtension&gt;
&lt;/CustomAction&gt;
&lt;/Elements&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://tomaszrabinski.pl/wordpress/2012/02/25/enable-or-disable-custom-ribbon-button-in-sharepoint-2010/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://tomaszrabinski.pl/wordpress/2012/02/25/enable-or-disable-custom-ribbon-button-in-sharepoint-2010/</feedburner:origLink></item>
		<item>
		<title>Get selected items from SharePoint 2010 list</title>
		<link>http://feedproxy.google.com/~r/TomaszRabinskiZavazBlog/~3/pYu2PgrdJQU/</link>
		<comments>http://tomaszrabinski.pl/wordpress/2012/02/25/get-selected-list-items-sharepoint-2010/#comments</comments>
		<pubDate>Sat, 25 Feb 2012 14:00:55 +0000</pubDate>
		<dc:creator>zavaz</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[SharePoint 2010]]></category>
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://tomaszrabinski.pl/?p=572</guid>
		<description><![CDATA[Fetching selected list items in SharePoint 2010 is very simple. To achieve such a functionality You can use Custom Ribbon Button. In this example I will use the code from my previous post on creating custom ribbon button. The code that let&#8217;s You fetch selected list items looks like this: When You have the selected [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.flickr.com/photos/igboo/"><img class="alignleft" style="margin-right: 10px; margin-bottom: 5px;" title="Select" src="http://farm4.staticflickr.com/3200/3039567885_63889af9c8_t.jpg" alt="" width="100" height="100" /></a>Fetching selected list items in SharePoint 2010 is very simple. To achieve such a functionality You can use Custom Ribbon Button. In this example I will use the code from my <a title="PREVIOUS POST" href="http://tomaszrabinski.pl/wordpress/2012/02/25/sharepoint-2010-custom-ribbon-button/" target="_blank">previous post</a> on creating custom ribbon button.<span id="more-572"></span></p>
<p>The code that let&#8217;s You fetch selected list items looks like this:</p>
<pre class="brush: csharp; title: ; notranslate">

var ctx = SP.ClientContext.get_current();
 var items = SP.ListOperation.Selection.getSelectedItems(ctx);
 var myItems = '';
 var i;

 for (i in items)
 {
 myItems += '|' + items[i].id;
 }
</pre>
<p>When You have the selected items id&#8217;s, then You can for example pass them to the new page by opening new modal dialog with prepared query string:</p>
<pre class="brush: csharp; title: ; notranslate">

function resultCallback(result, value)
 {
 SP.UI.Notify.addNotification('Success!');
 SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.OK);
 }

var ctx = SP.ClientContext.get_current();
var items = SP.ListOperation.Selection.getSelectedItems(ctx);
var myItems = '';
var i;

for (i in items)
{
myItems += '|' + items[i].id;
}

 if(myItems != '')
 {
 var options = {
 url: '{SiteUrl}/_layouts/MyPage.aspx?Items=' + myItems + '&amp;amp;ListId={SelectedListId}&amp;amp;Source={Source}',
 tite: 'My Page',
 allowMaximize: false,
 showClose: true,
 width: 500,
 height: 160,
 dialogReturnValueCallback: resultCallback };

 SP.UI.ModalDialog.showModalDialog(options);
 }
</pre>
<p>Full elements.xml looks like this:</p>
<pre class="brush: xml; title: ; notranslate">

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?&gt;
&lt;Elements xmlns=&quot;http://schemas.microsoft.com/sharepoint/&quot;&gt;

&lt;CustomAction

Id=&quot;CAAlertRibbonButton&quot;
RegistrationId=&quot;100&quot;
RegistrationType=&quot;List&quot;
Location=&quot;CommandUI.Ribbon&quot;
Sequence=&quot;5&quot;
Title=&quot;Alert Ribbon Button&quot;&gt;

&lt;CommandUIExtension&gt;
&lt;CommandUIDefinitions&gt;
&lt;CommandUIDefinition Location=&quot;Ribbon.List.Settings.Controls._children&quot;&gt;
&lt;Button
Id=&quot;AlertRibbonButtonId&quot;
Alt=&quot;Alert Ribbon Button&quot;
Sequence=&quot;5&quot;
Command=&quot;CMDAlertRibbonButton&quot;
Image32by32=&quot;/_layouts/images/menulistsettings.gif&quot;
Image16by16=&quot;/_layouts/images/itdcl.gif&quot;
LabelText=&quot;Alert Ribbon Button&quot;
TemplateAlias=&quot;o1&quot; /&gt;
&lt;/CommandUIDefinition&gt;
&lt;/CommandUIDefinitions&gt;

&lt;CommandUIHandlers&gt;
&lt;CommandUIHandler
Command=&quot;CMDAlertRibbonButton&quot;
CommandAction=&quot;javascript:
function resultCallback(result, value)
 {
 SP.UI.Notify.addNotification('Success!');
 SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.OK);
 }

var ctx = SP.ClientContext.get_current();
var items = SP.ListOperation.Selection.getSelectedItems(ctx);
var myItems = '';
var i;

for (i in items)
{
myItems += '|' + items[i].id;
}

if(myItems != '')
 {
 var options = {
 url: '{SiteUrl}/_layouts/MyPage.aspx?Items=' + myItems + '&amp;amp;ListId={SelectedListId}&amp;amp;Source={Source}',
 tite: 'My Page',
 allowMaximize: false,
 showClose: true,
 width: 500,
 height: 160,
 dialogReturnValueCallback: resultCallback };

SP.UI.ModalDialog.showModalDialog(options);
 }&quot; /&gt;
&lt;/CommandUIHandlers&gt;

&lt;/CommandUIExtension&gt;
&lt;/CustomAction&gt;
&lt;/Elements&gt;
</pre>
<p>To retrieve the id&#8217;s in the page opened using modal dialog use below code:</p>
<pre class="brush: csharp; title: ; notranslate">

string[] items = Request[&quot;Items&quot;] != null ? Request[&quot;Items&quot;].Split(new string[] { &quot;|&quot; }, StringSplitOptions.RemoveEmptyEntries) : new string[] { };//get id's

SPList list = null;

SPSecurity.RunWithElevatedPrivileges(() =&gt;
 {
 using (SPSite site = new SPSite(sourceUrl))
 {
 using (SPWeb web = site.OpenWeb())
 {
 list = web.Lists[new Guid(Request[&quot;ListId&quot;])];//get list reference in elevated mode
 }
 }
 });

foreach (string id in Items)
 {
 var listItem = list.GetItemById(Int32.Parse(id));//Fetch list item

//DO SOME ACTION

}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://tomaszrabinski.pl/wordpress/2012/02/25/get-selected-list-items-sharepoint-2010/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://tomaszrabinski.pl/wordpress/2012/02/25/get-selected-list-items-sharepoint-2010/</feedburner:origLink></item>
		<item>
		<title>SharePoint 2010 Custom Ribbon Button</title>
		<link>http://feedproxy.google.com/~r/TomaszRabinskiZavazBlog/~3/yir1O8-sAvU/</link>
		<comments>http://tomaszrabinski.pl/wordpress/2012/02/25/sharepoint-2010-custom-ribbon-button/#comments</comments>
		<pubDate>Sat, 25 Feb 2012 11:40:56 +0000</pubDate>
		<dc:creator>zavaz</dc:creator>
				<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[SharePoint 2010]]></category>
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://tomaszrabinski.pl/?p=560</guid>
		<description><![CDATA[Ribbon in SharePoint 2010 comapring with previous versions of SharePoint is a big change and a vast improvement in the GUI. When You use it for the first time it can be a bit confusing, but You should get used to it very quickly. Very nice function implemented in the newest version of SharePoint is [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.flickr.com/photos/trygveu/"><img class="alignleft" style="margin-right: 10px; margin-botton: 5px;" title="Ribbon" src="http://farm3.staticflickr.com/2238/2448824654_af019017f7_m.jpg" alt="" width="118" height="139" /></a>Ribbon in SharePoint 2010 comapring with previous versions of SharePoint is a big change and a vast improvement in the GUI. When You use it for the first time it can be a bit confusing, but You should get used to it very quickly. Very nice function implemented in the newest version of SharePoint is ability to customize nad create Your own Ribbon Buttons. To create such a custom button You have to create a new Feature and deploy it on the SharePoint server.<span id="more-560"></span></p>
<p>Buttons can be created for different kind of lists and in different Ribbon Groups. Right now I will show You how to create a Ribbon Button for Custom List placed in the Settings group. For the full list of Ribbon locations go <a title="HERE" href="http://msdn.microsoft.com/en-us/library/ee537543.aspx" target="_blank">HERE</a>.</p>
<p>First You have to create a new Feature. I will create a Feature which will be activated on a site collection level, which means that after Feature activation all the Custom Lists in the site collection will contain this button:</p>
<pre class="brush: xml; title: ; notranslate">

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;Feature Id=&quot;145cea3f-acf2-4166-915a-48174e284ff7&quot;
 Title=&quot;Alert Button&quot;
 Description=&quot;&quot;
 Version=&quot;1.0.0.0&quot;
 Hidden=&quot;FALSE&quot;
 Scope=&quot;Site&quot;
 DefaultResourceFile=&quot;core&quot;
 xmlns=&quot;http://schemas.microsoft.com/sharepoint/&quot;&gt;
 &lt;ElementManifests&gt;
 &lt;ElementManifest Location=&quot;elements.xml&quot;/&gt;
 &lt;/ElementManifests&gt;
&lt;/Feature&gt;
</pre>
<p>Now for the Elements.xml:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?&gt;
&lt;Elements xmlns=&quot;http://schemas.microsoft.com/sharepoint/&quot;&gt;

&lt;CustomAction

Id=&quot;CAAlertRibbonButton&quot;
RegistrationId=&quot;100&quot;
RegistrationType=&quot;List&quot;
Location=&quot;CommandUI.Ribbon&quot;
Sequence=&quot;5&quot;
Title=&quot;Alert Ribbon Button&quot;&gt;

&lt;CommandUIExtension&gt;
&lt;CommandUIDefinitions&gt;
&lt;CommandUIDefinition Location=&quot;Ribbon.List.Settings.Controls._children&quot;&gt;
&lt;Button
Id=&quot;AlertRibbonButtonId&quot;
Alt=&quot;Alert Ribbon Button&quot;
Sequence=&quot;5&quot;
Command=&quot;CMDAlertRibbonButton&quot;
Image32by32=&quot;/_layouts/images/menulistsettings.gif&quot;
Image16by16=&quot;/_layouts/images/itdcl.gif&quot;
LabelText=&quot;Alert Ribbon Button&quot;
TemplateAlias=&quot;o1&quot; /&gt;
&lt;/CommandUIDefinition&gt;
&lt;/CommandUIDefinitions&gt;

&lt;CommandUIHandlers&gt;
&lt;CommandUIHandler
Command=&quot;CMDAlertRibbonButton&quot;
CommandAction=&quot;javascript: alert('List Id: {SelectedListId}');&quot; /&gt;
&lt;/CommandUIHandlers&gt;

&lt;/CommandUIExtension&gt;
&lt;/CustomAction&gt;
&lt;/Elements&gt;
</pre>
<p>The result:</p>
<p><a href="http://tomaszrabinski.pl/wordpress/wp-content/uploads/2012/02/Ribbon.png"><img class="aligncenter size-full wp-image-564" title="Ribbon" src="http://tomaszrabinski.pl/wordpress/wp-content/uploads/2012/02/Ribbon.png" alt="" width="1256" height="134" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://tomaszrabinski.pl/wordpress/2012/02/25/sharepoint-2010-custom-ribbon-button/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://tomaszrabinski.pl/wordpress/2012/02/25/sharepoint-2010-custom-ribbon-button/</feedburner:origLink></item>
		<item>
		<title>SharePoint and NHibernate – problem with NHibernate.ByteCode.Castle.dll</title>
		<link>http://feedproxy.google.com/~r/TomaszRabinskiZavazBlog/~3/XGoHvURSMSI/</link>
		<comments>http://tomaszrabinski.pl/wordpress/2011/12/29/sharepoint-and-nhibernate-problem-with-nhibernate-bytecode-castle-dll/#comments</comments>
		<pubDate>Thu, 29 Dec 2011 12:14:51 +0000</pubDate>
		<dc:creator>zavaz</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://tomaszrabinski.pl/?p=539</guid>
		<description><![CDATA[I often use NHibernate to work with SQL database. It&#8217;s a very mature ORM solution for .NET which allows You to freeley &#8220;talk&#8221; with any database. Although, this is very simple ORM, sometimes I have some challanges I have to face. One of the first issue I had with this ORM was: Could not load [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.flickr.com/photos/billjacobus1/"><img class="alignleft" style="margin-right: 10px;" title="Error" src="http://farm3.staticflickr.com/2299/2482521750_1c36bbc5e8_m.jpg" alt="" width="173" height="112" /></a>I often use NHibernate to work with SQL database. It&#8217;s a very mature ORM solution for .NET which allows You to freeley &#8220;talk&#8221; with any database. Although, this is very simple ORM, sometimes I have some challanges I have to face.</p>
<p>One of the first issue I had with this ORM was:</p>
<h2><em>Could not load file or assembly &#8216;NHibernate.ByteCode.Castle&#8217; or one of its dependencies. The system cannot find the file specified.</em></h2>
<p><span id="more-539"></span>The message was clear. Somehow my solution couldn&#8217;t find  NHibernate.ByteCode.Castle.dll. First I checked the references in my project &#8211; they were OK. Than I checked if the dll is in the GAC &#8211; It was. Running out of ideas I started to read the error message carefoully and I focused on one part:</p>
<p><a href="http://tomaszrabinski.pl/wordpress/wp-content/uploads/2011/12/2011-12-29_115914.jpg"><img class="aligncenter size-full wp-image-540" title="2011-12-29_115914" src="http://tomaszrabinski.pl/wordpress/wp-content/uploads/2011/12/2011-12-29_115914.jpg" alt="" width="851" height="71" /></a></p>
<p>According to this message I should turn on the Assembly binding logging to see what is wrong. I went to HKLM\Software\Microsoft\Fusion and created new DWORD value set to 1. After refreshing the error page I noticed a new thing:</p>
<p><a href="http://tomaszrabinski.pl/wordpress/wp-content/uploads/2011/12/2011-12-29_120223.jpg"><img class="aligncenter size-full wp-image-542" title="2011-12-29_120223" src="http://tomaszrabinski.pl/wordpress/wp-content/uploads/2011/12/2011-12-29_120223.jpg" alt="" width="830" height="263" /></a></p>
<p>After that everything was clear. Application have been searching for the dll in the wrong directory &#8211; bin instead of GAC. To fix this I could modify the web.config, but I really don&#8217;t like to change contents of this file, unless I really have to. I figured out that I can modify my code, so it will be able to resolve NHibernate.ByteCode.Castle.dll. Before modifications the code looked like this:</p>
<pre class="brush: csharp; title: ; notranslate">

public static class NHibernateHelper
 {

public static ISessionFactory GetSessionFactory(bool throwExceptionOnFail)
 {
 var cfg = Fluently.Configure().Database(MsSqlConfiguration.MsSql2008.UseOuterJoin().ConnectionString(x =&gt; x.Server(&quot;SERVER&quot;).Username(&quot;USERNAME&quot;).Password(&quot;PASSWORD&quot;).Database(&quot;DATABASE&quot;))).Mappings(x =&gt; x.FluentMappings.AddFromAssembly(Assembly.GetExecutingAssembly()));

return cfg.BuildSessionFactory();

}

}
</pre>
<p>After modifications:</p>
<pre class="brush: csharp; title: ; notranslate">

public static class NHibernateHelper
 {
 public static ISessionFactory GetSessionFactory()
 {
 return GetSessionFactory(false);
 }

private static ISessionFactory GetSessionFactory(bool throwExceptionOnFail)
 {
 try
 {
 var cfg = Fluently.Configure().Database(MsSqlConfiguration.MsSql2008.UseOuterJoin().ConnectionString(x =&gt; x.Server(&quot;SERVER&quot;).Username(&quot;USER&quot;).Password(&quot;PASSWORD&quot;).Database(&quot;DATABASE&quot;))).Mappings(x =&gt; x.FluentMappings.AddFromAssembly(Assembly.GetExecutingAssembly()));

return cfg.BuildSessionFactory();//This will throw an error first time after application pool recycle/reset.
 }
 catch(FileNotFoundException)
 {
 if (throwExceptionOnFail)
 throw;

AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);//Add the resolve event handler

var sessionFactory = GetSessionFactory(true);

AppDomain.CurrentDomain.AssemblyResolve -= new ResolveEventHandler(CurrentDomain_AssemblyResolve);//Remove the event, because the assembly has been already loaded to the current application domain and will stay there until next application pool recycle/reset

return sessionFactory;
 }
 }

static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
 {
 if (args.Name.ToLower() == &quot;NHibernate.ByteCode.Castle&quot;.ToLower())
 return Assembly.Load(&quot;NHibernate.ByteCode.Castle, version=3.1.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4&quot;);

 return null;
 }
 }
</pre>
<p>Notice the &#8220;AppDomain.CurrentDomain.AssemblyResolve&#8221; part. I added the event handler to the current application domain which will fire when any of the DLL&#8217;s can&#8217;t be resolved. Inside the event handler I check if the missing DLL is NHibernate.ByteCode.Castle. If so, then I load it &#8220;manually&#8221; and return the Assembly object which will exist in the current application domain until application pool is beeing recycled or reset. The &#8220;catch&#8221; code will execute only the first time after new application domain is created(after application pool recycle/reset). Every next time only the &#8220;try&#8221; code will be executed.</p>
<p>Now, to get the ISessionFactory object without any errors only one method should be called:</p>
<pre class="brush: csharp; title: ; notranslate">

var sf = NHibernateHelper.GetSessionFactory()
</pre>
<p>Of course this is not a perfect solution. For example if You replace NHibernate.ByteCode.Castle.dll with a newer version, above code won&#8217;t work. Then You will have to make a redirect to this new version.</p>
]]></content:encoded>
			<wfw:commentRss>http://tomaszrabinski.pl/wordpress/2011/12/29/sharepoint-and-nhibernate-problem-with-nhibernate-bytecode-castle-dll/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://tomaszrabinski.pl/wordpress/2011/12/29/sharepoint-and-nhibernate-problem-with-nhibernate-bytecode-castle-dll/</feedburner:origLink></item>
		<item>
		<title>SharePoint 2010 Developer Dashboard</title>
		<link>http://feedproxy.google.com/~r/TomaszRabinskiZavazBlog/~3/Ci4Y35GKkOI/</link>
		<comments>http://tomaszrabinski.pl/wordpress/2011/11/24/sharepoint-2010-developer-dashboard/#comments</comments>
		<pubDate>Thu, 24 Nov 2011 20:51:40 +0000</pubDate>
		<dc:creator>zavaz</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[SharePoint 2010]]></category>

		<guid isPermaLink="false">http://tomaszrabinski.pl/?p=524</guid>
		<description><![CDATA[Developer dashboard is a new feature in SharePoint. It provides to developers and administrators performance and tracing information that can be used to debug and troubleshoot issues with a page rendering time. The dashboard is turned off by default but it can be enabled through C# code, stsadm or powershell command and it can have three [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://tomaszrabinski.pl/wordpress/wp-content/uploads/2011/11/schoolboard.jpg"><img class="alignleft size-full wp-image-534" style="margin-right: 10px;" title="schoolboard" src="http://tomaszrabinski.pl/wordpress/wp-content/uploads/2011/11/schoolboard.jpg" alt="" width="122" height="122" /></a>Developer dashboard is a new feature in SharePoint. It provides to developers and administrators performance and tracing information that can be used to debug and troubleshoot issues with a page rendering time. The dashboard is turned off by default but it can be enabled through C# code, stsadm or powershell command and it can have three states: On, Off, OnDemand. First two should be clear. Third one means that SharePoint will show an image button next to Your login name on a page with which You will be able to show or hide the developer dashboard.</p>
<p><span id="more-524"></span></p>
<p>To turn it on:</p>
<ul>
<li>C#</li>
</ul>
<pre class="brush: csharp; title: ; notranslate">

SPWebService webService = SPWebService.ContentService;
webService.DeveloperDashboardSettings.DisplayLevel = SPDeveloperDashboardLevel.OnDemand;
webService.DeveloperDashboardSettings.Provision();
</pre>
<ul>
<li>Stsadm.exe</li>
</ul>
<pre class="brush: csharp; title: ; notranslate">

stsadm -o setproperty -pn developer-dashboard -pv [ondemand] [on] [off]
</pre>
<ul>
<li>Powershell</li>
</ul>
<pre class="brush: csharp; title: ; notranslate">
$db = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
$dbSettings = $db.DeveloperDashboardSettings
$dbSettings.DisplayLevel = [Microsoft.SharePoint.Administration.SPDeveloperDashboardLevel]::OnDemand
$dbSettings.Update()
</pre>
<p>Image Button next to the login details:</p>
<p><a href="http://tomaszrabinski.pl/wordpress/wp-content/uploads/2011/11/DeveloperDasboardImageButton.png"><img class="aligncenter size-full wp-image-529" title="DeveloperDasboardImageButton" src="http://tomaszrabinski.pl/wordpress/wp-content/uploads/2011/11/DeveloperDasboardImageButton.png" alt="" width="188" height="34" /></a></p>
<p>When a dashboard is shown You can see the details about rendering time of every Web Part, executed SQL queries and general information about the page execution.</p>
<p><a href="http://tomaszrabinski.pl/wordpress/wp-content/uploads/2011/11/DeveloperDashboard.png"><img class="aligncenter size-full wp-image-525" title="DeveloperDashboard" src="http://tomaszrabinski.pl/wordpress/wp-content/uploads/2011/11/DeveloperDashboard.png" alt="" width="824" height="525" /></a></p>
<p>On the left side of the dashboard You can see sites&#8217; rendering time. It&#8217;s divided for different processes which have been executed while site has been created. On the top right You have a general information about the site like overall execution time, current user or correlation id which can be very usefull along with ULS viewer tool which allows You to go view SharePoint logs. Next are executed database queries. You can see that they are really hyperlinks which when cliked will open a new window with the query details(as shown on the below screenshot).</p>
<p><a href="http://tomaszrabinski.pl/wordpress/wp-content/uploads/2011/11/DeveloperDashboardQuery.png"><img class="aligncenter size-full wp-image-527" title="DeveloperDashboardQuery" src="http://tomaszrabinski.pl/wordpress/wp-content/uploads/2011/11/DeveloperDashboardQuery.png" alt="" width="810" height="825" /></a></p>
<p>Another information about the page execution are SPRequest Allocation entries. This is very important to developers. It shows how many SPWeb(and SPRequest along with them) objects are created. Large number(default threshold is eight) of this objects along side with not disposing them properly can cause seriuos memory leaking and performance problems.</p>
<p>Web Part Events Offsets show the execution time of the standard events which You override when You create a new Web Part. It&#8217;s very useful because here You can see which of the methods takes the most time to execute and where is the bottleneck.</p>
<p>To measure the execution time of Your custom code, for example button OnClick event, You can use C# SPMonitoredScope class. It allows You to measure the execution time of Your code and shows it on the left side of the dashboard. To use it You have  wrap Your code in a using statement like shown below:</p>
<pre class="brush: csharp; title: ; notranslate">

using(SPMonitoredScope ms = new SPMonitoredScope(&quot;NameShownOnTheLeftSideOfDashboard&quot;))

{

//Your code goes here

}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://tomaszrabinski.pl/wordpress/2011/11/24/sharepoint-2010-developer-dashboard/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://tomaszrabinski.pl/wordpress/2011/11/24/sharepoint-2010-developer-dashboard/</feedburner:origLink></item>
		<item>
		<title>SharePoint SPItemEventReceiver</title>
		<link>http://feedproxy.google.com/~r/TomaszRabinskiZavazBlog/~3/Ym-PM56X5C4/</link>
		<comments>http://tomaszrabinski.pl/wordpress/2011/11/24/sharepoint-spitemeventreceiver/#comments</comments>
		<pubDate>Thu, 24 Nov 2011 17:35:34 +0000</pubDate>
		<dc:creator>zavaz</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[SharePoint 2010]]></category>
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://tomaszrabinski.pl/?p=511</guid>
		<description><![CDATA[Item event receivers are similar to triggers existing in databases. They are executed on certain moments(events) on a SharePoint lists, libraries etc. Thanks to the events You can control Your items content, perform necessary validation before commiting any changes to the item. There are many types ov event receivers, but the most popular are: ItemAdding [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://tomaszrabinski.pl/wordpress/wp-content/uploads/2011/11/spLogo.png"><img class="alignleft size-thumbnail wp-image-515" style="margin-right: 10px;" title="spLogo" src="http://tomaszrabinski.pl/wordpress/wp-content/uploads/2011/11/spLogo-150x150.png" alt="" width="120" height="120" /></a>Item event receivers are similar to triggers existing in databases. They are executed on certain moments(events) on a SharePoint lists, libraries etc. Thanks to the events You can control Your items content, perform necessary validation before commiting any changes to the item.</p>
<p><span id="more-511"></span></p>
<p>There are many types ov event receivers, but the most popular are:</p>
<ul>
<li>ItemAdding &#8211; fired before new item is added</li>
<li>ItemAdded &#8211; fired after new item is added</li>
<li>ItemUpdating &#8211; fired before existing item is updated</li>
<li>ItemUpdated &#8211; fired after existing item is updated</li>
<li>ItemDeleting &#8211; fired before existing item is deleted</li>
<li>ItemDeleted &#8211; fired after existing item is deleted</li>
</ul>
<p>Below You can find the code used to create a class with will handle ItemAdding event:</p>
<pre class="brush: csharp; title: ; notranslate">
public class OnItemAdding : SPItemEventReceiver//You have to inherit from SPItemEventReceiver class
    {
        public override void ItemAdding(SPItemEventProperties properties)
        {
            try
            {
               this.DisableEventFiring();//Disable any other events while our event is beeing executed

                base.ItemAdding(properties);//Call base class event

                //Perform some actions, f.e. check if the Title colomn is not empty
                if(String.IsNullOrEmpty(properties.AfterProperties[&quot;Title&quot;] + String.Empty))
                {
                   throw new ApplicationException(&quot;Field 'Title' should not be empty&quot;);
}
                else
                {
                   //Field is not empty
                   properties.Cancel = false;//We do not want to cancel the event
                   properties.Status = SPEventReceiverStatus.Continue;//We want to continue the process
                   properties.ErrorMessage = String.Empty;//There is no error message
                }
            }
            catch (Exception ex)
            {
                //Exception occurred
                properties.Cancel = true;//We cancel the event
                properties.Status = SPEventReceiverStatus.CancelWithError;//Set appropriate status
                properties.ErrorMessage = ex.Message;//Set the error message
            }
            finally
            {
                this.EnableEventFiring();//Regardless if the exception occurred or not, we have to enable earlier disabled events
            }
        }
    }
</pre>
<p>With the class like that we can add out event receiver to the list using the code:</p>
<pre class="brush: csharp; title: ; notranslate">
SPList list = GetElevatedList(listId);//We have to get the list in the elevated mode to be sure that we have the needed permissions. We can do that using the SPSecurity.RunWithElevatedPrivileges described in some previous post

string assemblyQualifiedName = &quot;MyApp.Forms, version=1.0.0.0, culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxxA&quot;;//You can use System.Reflection.Assembly.GetExecutingAssembly().FullName
string receiverClass = &quot;MyApp.Forms.EventReceivers.OnItemAdding&quot;//Namespace.ClassName
SPEventReceiverType receiverType = SPEventReceiverType.ItemAdding;

SPEventReceiverDefinition eRecv = list.EventReceivers.OfType&lt;SPEventReceiverDefinition&gt;().Where(recv =&gt; recv.Class == receiverClass).FirstOrDefault();

if (eRecv == null)
{
    bool allowUnsafeUpdates = list.ParentWeb.AllowUnsafeUpdates;
    list.ParentWeb.AllowUnsafeUpdates = true;
    list.EventReceivers.Add(receiverType, assemblyQualifiedName, receiverClass);
    list.ParentWeb.AllowUnsafeUpdates = allowUnsafeUpdates;
}
</pre>
<p>To disable added receiver:</p>
<pre class="brush: csharp; title: ; notranslate">
SPList list = GetElevatedList(listId);

string receiverClass = &quot;MyApp.Forms.EventReceivers.OnItemAdding&quot;//Namespace.ClassName

SPEventReceiverDefinition eRecv = list.EventReceivers.OfType&lt;SPEventReceiverDefinition&gt;().Where(recv =&gt; recv.Class == receiverClass).FirstOrDefault();

if (eRecv != null)
{
    bool allowUnsafeUpdates = list.ParentWeb.AllowUnsafeUpdates;
    list.ParentWeb.AllowUnsafeUpdates = true;
    eRecv.Delete();
    list.ParentWeb.AllowUnsafeUpdates = allowUnsafeUpdates;
}
</pre>
<p>The most important thing You have to remember about is to not use the SPContext.Current property, becasue the current context in event receivers is always equal to null. If You need a SPWeb object You can use:</p>
<pre class="brush: csharp; title: ; notranslate">
properties.OpenWeb();
</pre>
]]></content:encoded>
			<wfw:commentRss>http://tomaszrabinski.pl/wordpress/2011/11/24/sharepoint-spitemeventreceiver/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://tomaszrabinski.pl/wordpress/2011/11/24/sharepoint-spitemeventreceiver/</feedburner:origLink></item>
		<item>
		<title>You need help with Your SharePoint? SharePoint 4 Business is for You!</title>
		<link>http://feedproxy.google.com/~r/TomaszRabinskiZavazBlog/~3/eyxUb5Ewpks/</link>
		<comments>http://tomaszrabinski.pl/wordpress/2011/11/04/sharepoint-4-business/#comments</comments>
		<pubDate>Fri, 04 Nov 2011 10:58:26 +0000</pubDate>
		<dc:creator>zavaz</dc:creator>
				<category><![CDATA[Commercial]]></category>
		<category><![CDATA[SharePoint 2010]]></category>

		<guid isPermaLink="false">http://tomaszrabinski.pl/?p=469</guid>
		<description><![CDATA[SharePoint 4 Business We are a team of IT engineers specializing in Microsoft SharePoint technology. Thanks to precise expertise We are able to successfully execute our clients&#8217; business needs related to information systems. Our experience allows us to support the implementation of modern systems based on a SharePoint platform. &#160; Our goal is to provide [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://sps4.biz/"><img class="aligncenter" title="SharePont 4 Business" src="http://sharepointblog.pl/wp-content/gallery/cache/61__400x142_logo400-copy.jpg" alt="" width="400" height="142" /></a><span id="more-469"></span></p>
<h1 style="text-align: center;"><a href="http://sps4.biz/">SharePoint 4 Business</a></h1>
<p style="text-align: justify;">We are a team of IT engineers specializing in Microsoft SharePoint technology. Thanks to precise expertise We are able to successfully execute our clients&#8217; business needs related to information systems. Our experience allows us to support the implementation of modern systems based on a SharePoint platform.</p>
<p style="text-align: justify;">&nbsp;</p>
<p style="text-align: justify;">Our goal is to provide our customers the best quality solutions and expertise that will enable the effective implementation of business projects.</p>
<p style="text-align: justify;">&nbsp;</p>
<p style="text-align: justify;">Services we offer include:</p>
<ul>
<li style="text-align: justify;">     SharePoint Deployments</li>
<li style="text-align: justify;">     SharePoint Hosting Services</li>
<li style="text-align: justify;">     Consulting</li>
<li style="text-align: justify;">     Trainings</li>
<li style="text-align: justify;">     Preparation of dedicated systems based on the Clients&#8217; requirements</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://tomaszrabinski.pl/wordpress/2011/11/04/sharepoint-4-business/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://tomaszrabinski.pl/wordpress/2011/11/04/sharepoint-4-business/</feedburner:origLink></item>
		<item>
		<title>Preventing browser from cachning ASPX or ASCX content</title>
		<link>http://feedproxy.google.com/~r/TomaszRabinskiZavazBlog/~3/_Z6ClfCPckM/</link>
		<comments>http://tomaszrabinski.pl/wordpress/2011/08/31/preventing-browser-from-cachning-aspx-or-ascx-content/#comments</comments>
		<pubDate>Wed, 31 Aug 2011 14:49:36 +0000</pubDate>
		<dc:creator>zavaz</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Commercial]]></category>
		<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://tomaszrabinski.pl/?p=460</guid>
		<description><![CDATA[Caching content by the browsers can be sometimes very annoying. I had problems with it,  mostly when I was developing some popup modal dialogs which showed aspx or ascx controls. Thankfully, there is very simple solution how to disable content caching. You achieve it in two ways: 1. Directly in the ASPX or ASCX using [...]]]></description>
			<content:encoded><![CDATA[<p>Caching content by the browsers can be sometimes very annoying. I had problems with it,  mostly when I was developing some popup modal dialogs which showed aspx or ascx controls.</p>
<p>Thankfully, there is very simple solution how to disable content caching. You achieve it in two ways:</p>
<p><span id="more-460"></span></p>
<p>1. Directly in the ASPX or ASCX using below code:</p>
<pre class="brush: csharp; title: ; notranslate">

&lt;% System.Web.HttpContext.Current.Response.AddHeader( &quot;Cache-Control&quot;,&quot;no-cache&quot;);
System.Web.HttpContext.Current.Response.Expires = 0;
System.Web.HttpContext.Current.Response.Cache.SetNoStore();
System.Web.HttpContext.Current.Response.AddHeader(&quot;Pragma&quot;, &quot;no-cache&quot;);%&gt;
</pre>
<p>2. From the codebehind, for example in the OnLoad event:</p>
<pre class="brush: csharp; title: ; notranslate">

protected override void OnLoad(EventArgs e)

{

System.Web.HttpContext.Current.Response.AddHeader( &quot;Cache-Control&quot;,&quot;no-cache&quot;);
System.Web.HttpContext.Current.Response.Expires = 0;
System.Web.HttpContext.Current.Response.Cache.SetNoStore();
System.Web.HttpContext.Current.Response.AddHeader(&quot;Pragma&quot;, &quot;no-cache&quot;);

}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://tomaszrabinski.pl/wordpress/2011/08/31/preventing-browser-from-cachning-aspx-or-ascx-content/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://tomaszrabinski.pl/wordpress/2011/08/31/preventing-browser-from-cachning-aspx-or-ascx-content/</feedburner:origLink></item>
		<item>
		<title>The List cannot be displayed in Datasheet view Error</title>
		<link>http://feedproxy.google.com/~r/TomaszRabinskiZavazBlog/~3/b5VTw8-yx7g/</link>
		<comments>http://tomaszrabinski.pl/wordpress/2011/08/24/the-list-cannot-be-displayed-in-datasheet-view-error/#comments</comments>
		<pubDate>Wed, 24 Aug 2011 16:55:56 +0000</pubDate>
		<dc:creator>zavaz</dc:creator>
				<category><![CDATA[Commercial]]></category>
		<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://tomaszrabinski.pl/?p=451</guid>
		<description><![CDATA[I often use Datasheet view in SharePoint to manipulate the data from the list. Few times I&#8217;ve met with the error &#8220;The List cannot be displayed in Datasheet view&#8221; when I tried to open the &#8220;excel&#8221; view. This can be caused by an Office 2010 64-bit version installation on the local PC or even by [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.flickr.com/photos/mangpages/"><img class=" alignleft" style="margin-right: 10px;" title="Error" src="http://farm5.static.flickr.com/4108/5042888638_1d8c9d4d1d_m.jpg" alt="" width="146" height="109" /></a>I often use Datasheet view in SharePoint to manipulate the data from the list. Few times I&#8217;ve met with the error &#8220;The List cannot be displayed in Datasheet view&#8221; when I tried to open the &#8220;excel&#8221; view.</p>
<p>This can be caused by an Office 2010 64-bit version installation on the local PC or even by the SharePoint Designer 2010 and happens only in Windows SharePoint Services 3.0(WSS) and Microsoft Office SharePoint Server 2007(MOSS).</p>
<p><span id="more-451"></span></p>
<p><a href="http://tomaszrabinski.pl/wordpress/wp-content/uploads/2011/08/DatasheetViewError.png"><img class="aligncenter size-full wp-image-452" title="DatasheetViewError" src="http://tomaszrabinski.pl/wordpress/wp-content/uploads/2011/08/DatasheetViewError.png" alt="" width="462" height="143" /></a></p>
<p>The very simple solution for this is to install 2007 Office System Driver: Data Connectivity Components available <a title="here" href="http://www.microsoft.com/download/en/details.aspx?displaylang=en&amp;id=23734" target="_blank">here</a>. After installation the Datasheet view should be working again.</p>
]]></content:encoded>
			<wfw:commentRss>http://tomaszrabinski.pl/wordpress/2011/08/24/the-list-cannot-be-displayed-in-datasheet-view-error/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://tomaszrabinski.pl/wordpress/2011/08/24/the-list-cannot-be-displayed-in-datasheet-view-error/</feedburner:origLink></item>
		<item>
		<title>Custom Exceptions Handling</title>
		<link>http://feedproxy.google.com/~r/TomaszRabinskiZavazBlog/~3/FL_adl5nl5I/</link>
		<comments>http://tomaszrabinski.pl/wordpress/2011/07/27/custom-exceptions-handling/#comments</comments>
		<pubDate>Tue, 26 Jul 2011 22:16:19 +0000</pubDate>
		<dc:creator>zavaz</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Commercial]]></category>
		<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://tomaszrabinski.pl/?p=434</guid>
		<description><![CDATA[In this post I&#8217;ll show how I handle exceptions in the projects I develop. Some time ago I wrote a simple class which turned out to be very useful in exception handling and displaying it to the user. To use it You have to create a new instance of it and add it to the [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.flickr.com/photos/andrewbain/"><img class="alignleft" style="margin-bottom: 5px; margin-right: 10px;" title="BSOD" src="http://farm3.static.flickr.com/2070/2228633614_e26ea98fbe_m.jpg" alt="" width="153" height="119" /></a>In this post I&#8217;ll show how I handle exceptions in the projects I develop.</p>
<p>Some time ago I wrote a simple class which turned out to be very useful in exception handling and displaying it to the user. To use it You have to create a new instance of it and add it to the controls collection on the page. Then You can just add exceptions, through the appropriate method, which will be rendered as a HTML table. The class uses Render event to check if any exception has been added, if so the class renders appropriate HTML code which is shown to the user.</p>
<p><span id="more-434"></span></p>
<pre class="brush: csharp; title: ; notranslate">

public class ExceptionsManager : UserControl
{
private List&lt;ExceptionObject&gt; _exceptions;

public IList&lt;ExceptionObject&gt; Exceptions
{
get
{
return _exceptions.AsReadOnly();
}
}

public ExceptionsManager()
{
_exceptions = new List&lt;ExceptionObject&gt;();
}

public void AddException(Exception ex)
{
AddException(String.Empty, ex);
}

public void AddException(string message, Exception ex)
{
_exceptions.Add(new ExceptionObject(message, ex));
}

protected override void Render(HtmlTextWriter writer)
{
base.Render(writer);

if (_exceptions.Count &gt; 0)
{
StringBuilder sb = new StringBuilder();
sb.Append(&quot;&lt;table width='100%' cellpadding='0' cellspacing='0'&gt;&quot;);

int i = 0;
foreach (ExceptionObject eo in _exceptions)
{
i++;
string errorDivIdMain = &quot;dError_&quot; + this.ID + &quot;_&quot; + i;
sb.Append(&quot;&lt;tr&gt;&lt;td style='color: red'&gt;&quot; + i + &quot;.&quot; + (String.IsNullOrEmpty(eo.Message) ? String.Empty : &quot; &lt;b&gt;&quot; + eo.Message + &quot;&lt;/b&gt;.&quot;) + &quot; &quot; + eo.Exception.Message + &quot; &lt;a href='' onclick='document.getElementById(\&quot;&quot; + errorDivIdMain + &quot;\&quot;).style.display=\&quot;block\&quot;; return false;'&gt;[Show Stack Trace]&lt;/a&gt;&lt;div id=\&quot;&quot; + errorDivIdMain + &quot;\&quot; style=\&quot;display: none\&quot;&gt;&lt;br /&gt;&quot; + eo.Exception.StackTrace + &quot;&lt;/div&gt;&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt;&quot;);

int padding = 0;
Exception ex = eo.Exception;
while (ex.InnerException != null)
{
ex = ex.InnerException;
padding += 30;
string errorDivId = &quot;dError_&quot; + this.ID + &quot;_&quot; + i + &quot;_&quot; + padding;
sb.Append(&quot;&lt;tr class='&quot; + errorDivIdMain + &quot;' style='display: none'&gt;&lt;td style='color: red; padding-left: &quot; + padding + &quot;px'&gt;&lt;b&gt;INNER EXCEPTION:&lt;/b&gt; &quot; + ex.Message + &quot; &lt;a href='' onclick='document.getElementById(\&quot;&quot; + errorDivId + &quot;\&quot;).style.display=\&quot;block\&quot;; return false;'&gt;[Show Stack Trace]&lt;/a&gt;&lt;div id=\&quot;&quot; + errorDivId + &quot;\&quot; style=\&quot;display: none\&quot;&gt;&lt;br /&gt;&quot; + ex.StackTrace + &quot;&lt;/div&gt;&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt;&quot;);
}
}

sb.Append(&quot;&lt;/table&gt;&quot;);

writer.Write(sb.ToString());
}
}
}

public class ExceptionObject
{
public string Message { get; private set; }
public Exception Exception { get; private set; }

public ExceptionObject(string message, Exception ex)
{
Message = message;
Exception = ex;
}
}
</pre>
<p>To use it:</p>
<pre class="brush: csharp; title: ; notranslate">

protected void Page_Load(object sender, EventArgs e)
{
ExceptionsManager exMgr = new ExceptionsManager();
this.Controls.Add(exMgr);

try
{
Int32.Parse(&quot;TEST&quot;);
}
catch (Exception ex)
{
exMgr.AddException(ex);
}
}
</pre>
<p>Above code will result in the error:</p>
<p><a href="http://tomaszrabinski.pl/wordpress/wp-content/uploads/2011/07/EXMANAGER.png"><img class="alignleft size-full wp-image-435" title="EXMANAGER" src="http://tomaszrabinski.pl/wordpress/wp-content/uploads/2011/07/EXMANAGER.png" alt="" width="424" height="46" /></a></p>
<p>After clicking Show Stack Trace:</p>
<p><a href="http://tomaszrabinski.pl/wordpress/wp-content/uploads/2011/07/EXMANAGER_SST.png"><img class="alignleft size-full wp-image-436" title="EXMANAGER_SST" src="http://tomaszrabinski.pl/wordpress/wp-content/uploads/2011/07/EXMANAGER_SST.png" alt="" width="477" height="44" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://tomaszrabinski.pl/wordpress/2011/07/27/custom-exceptions-handling/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://tomaszrabinski.pl/wordpress/2011/07/27/custom-exceptions-handling/</feedburner:origLink></item>
	</channel>
</rss>

