<?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, 16 Jan 2012 08:33:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</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>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>0</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>
		<item>
		<title>Assembla – free svn</title>
		<link>http://feedproxy.google.com/~r/TomaszRabinskiZavazBlog/~3/cpHm41pyQX0/</link>
		<comments>http://tomaszrabinski.pl/wordpress/2011/06/24/assembla-free-svn/#comments</comments>
		<pubDate>Fri, 24 Jun 2011 10:00:25 +0000</pubDate>
		<dc:creator>zavaz</dc:creator>
				<category><![CDATA[Tools]]></category>
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://tomaszrabinski.pl/?p=416</guid>
		<description><![CDATA[Assembla is a free subversion for any types of projects. You can use it to store solution online, follow the changes you made(file versioning), share Your work etc. Using Assembla is free and the only thing You have to do is registering on the site and creating a new space for Your project. Additionally, with [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://tomaszrabinski.pl/wordpress/wp-content/uploads/2011/06/assembla-logo.gif"><img class="alignleft size-full wp-image-417" style="margin-right: 10px; maegin bottom: 5px;" title="assembla-logo" src="http://tomaszrabinski.pl/wordpress/wp-content/uploads/2011/06/assembla-logo.gif" alt="" width="120" height="50" /></a>Assembla is a free subversion for any types of projects. You can use it to store solution online, follow the changes you made(file versioning), share Your work etc. Using Assembla is free and the only thing You have to do is registering on the site and creating a new space for Your project.</p>
<p>Additionally, with a help of third-party tools it&#8217;s possible to extend Your Visual Studio 2005/2008/2010 with ability to manage Your Assembla source code. <span id="more-416"></span>To do that You have to have an account on Assembla along with created space for the project, then download and install two files: <a href="http://tortoisesvn.net/downloads.html" target="_blank">TortoiseSVN</a> and <a href="http://ankhsvn.open.collab.net/downloads" target="_blank">AnkhSVN</a>. After finished installing these files You have to open Your Visual Studio, go to Tools -&gt; Options -&gt; Source Control -&gt; Plug-In Selection and select the AnkhSVN plug-in:</p>
<p><a href="http://tomaszrabinski.pl/wordpress/wp-content/uploads/2011/06/AnkhSVN.png" target="_blank"><img class="size-medium wp-image-418 alignnone" title="AnkhSVN" src="http://tomaszrabinski.pl/wordpress/wp-content/uploads/2011/06/AnkhSVN-300x173.png" alt="" width="300" height="173" /></a></p>
<p>Next. right mouse button click on the solution name in the Visual Studio Solution Explorer and select &#8220;Add solution to Subversion&#8221;:</p>
<p><a href="http://tomaszrabinski.pl/wordpress/wp-content/uploads/2011/06/AddSubversion.png"><img class="alignnone size-medium wp-image-420" title="AddSubversion" src="http://tomaszrabinski.pl/wordpress/wp-content/uploads/2011/06/AddSubversion-300x264.png" alt="" width="300" height="264" /></a></p>
<p>In the newly opened window type in Your project name and Repository URL(url of the created space in the Assembla), select the location in the locations tree and click &#8220;OK&#8221;:</p>
<p><a href="http://tomaszrabinski.pl/wordpress/wp-content/uploads/2011/06/SVNSettings.png" target="_blank"><img class="alignnone size-medium wp-image-423" title="SVNSettings" src="http://tomaszrabinski.pl/wordpress/wp-content/uploads/2011/06/SVNSettings-278x300.png" alt="" width="278" height="300" /></a></p>
<p>After that You should see in Your solution files little icons which show You actual status of the file.</p>
<p><a href="http://tomaszrabinski.pl/wordpress/wp-content/uploads/2011/06/SVNOK.png"><img class="alignnone size-full wp-image-424" title="SVNOK" src="http://tomaszrabinski.pl/wordpress/wp-content/uploads/2011/06/SVNOK.png" alt="" width="247" height="112" /></a></p>
<p>If You edit any file the status icon will be changed to inform You that the file content has been changed.</p>
<p><a href="http://tomaszrabinski.pl/wordpress/wp-content/uploads/2011/06/SVNChanged.png"><img class="alignnone size-full wp-image-426" title="SVNChanged" src="http://tomaszrabinski.pl/wordpress/wp-content/uploads/2011/06/SVNChanged.png" alt="" width="246" height="105" /></a></p>
<p>To &#8220;check in&#8221; the file on the Assembla server You have to Commit the changes:</p>
<p><a href="http://tomaszrabinski.pl/wordpress/wp-content/uploads/2011/06/SVNCommit.png"><img class="alignnone size-medium wp-image-427" title="SVNCommit" src="http://tomaszrabinski.pl/wordpress/wp-content/uploads/2011/06/SVNCommit-300x60.png" alt="" width="300" height="60" /></a></p>
<p>The rest of the options I leave to You to discover. From my side I can really recommend You this way of working with the solutions, especially when You are working on the same project with someone and You want to share the source code among the team.</p>
]]></content:encoded>
			<wfw:commentRss>http://tomaszrabinski.pl/wordpress/2011/06/24/assembla-free-svn/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://tomaszrabinski.pl/wordpress/2011/06/24/assembla-free-svn/</feedburner:origLink></item>
		<item>
		<title>SqlMembershipProvider – Users management</title>
		<link>http://feedproxy.google.com/~r/TomaszRabinskiZavazBlog/~3/adj3J7XSrPM/</link>
		<comments>http://tomaszrabinski.pl/wordpress/2011/06/24/sqlmembershipprovider-users-management/#comments</comments>
		<pubDate>Fri, 24 Jun 2011 05:00:28 +0000</pubDate>
		<dc:creator>zavaz</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://tomaszrabinski.pl/?p=409</guid>
		<description><![CDATA[In the previous post I showed You how to manage roles for forms authentication. Now I&#8217;ll explain how to manage users from the code side. The main class which lets You manage users from provider is System.WebSecurity.SqlMembershipProvider class. To get the SqlMembershipProvider object You have to use System.Web.Security.Membership class and pass the name of the [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.flickr.com/photos/pagedooley/"><img class="alignleft" style="margin-right: 10px; maegin bottom: 5px;" title="Users" src="http://farm3.static.flickr.com/2089/1985059254_8296705a71_m.jpg" alt="" width="165" height="126" /></a>In the previous post I showed You how to manage roles  for forms authentication. Now I&#8217;ll explain how to manage users from the  code side.</p>
<p>The main class which lets You manage users from provider is <a href="http://msdn.microsoft.com/en-us/library/system.web.security.sqlmembershipprovider%28v=VS.90%29.aspx" target="_blank">System.WebSecurity.SqlMembershipProvider</a> class.</p>
<p>To get the SqlMembershipProvider object You have to use <a href="http://msdn.microsoft.com/en-us/library/system.web.security.membership%28v=VS.90%29.aspx" target="_blank">System.Web.Security.Membership</a> class and pass the name of the provider You want to obtain:<img title="More..." src="http://tomaszrabinski.pl/wordpress/wp-includes/js/tinymce/plugins/wordpress/img/trans.gif" alt="" /><span id="more-409"></span></p>
<pre class="brush: csharp; title: ; notranslate">

SqlMembershipProvider provider = Membership.Providers[&quot;ProviderName&quot;] as SqlMembershipProvider;
</pre>
<p>To get the list of all existing users in the provider:</p>
<pre class="brush: csharp; title: ; notranslate">

MembershipUserCollection users = provider.GetAllUsers();
</pre>
<p>To add a new user:</p>
<pre class="brush: csharp; title: ; notranslate">

MembershipCreateStatus createStatus;
provider.CreateUser(&quot;UserName&quot;, &quot;UserPassword&quot;, &quot;UserEmail&quot;, &quot;passwordQuestion&quot;, &quot;passwordAnswer&quot;, true, Guid.NewGuid(), out createStatus);
</pre>
<p>To delete user:</p>
<pre class="brush: csharp; title: ; notranslate">

provider.DeleteUser(&quot;UserName&quot;);
</pre>
<p>To get the user object:</p>
<pre class="brush: csharp; title: ; notranslate">

MembershipUser user = provider.GetUser(&quot;UserName&quot;, false);
</pre>
<p>To update user data after change:</p>
<pre class="brush: csharp; title: ; notranslate">

provider.UpdateUser(UserObject);
</pre>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://tomaszrabinski.pl/wordpress/2011/06/24/sqlmembershipprovider-users-management/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://tomaszrabinski.pl/wordpress/2011/06/24/sqlmembershipprovider-users-management/</feedburner:origLink></item>
		<item>
		<title>SqlMembershipProvider – Roles management</title>
		<link>http://feedproxy.google.com/~r/TomaszRabinskiZavazBlog/~3/liI_spLXdUY/</link>
		<comments>http://tomaszrabinski.pl/wordpress/2011/06/23/sqlmembershipprovider-roles-management/#comments</comments>
		<pubDate>Thu, 23 Jun 2011 18:19:04 +0000</pubDate>
		<dc:creator>zavaz</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://tomaszrabinski.pl/?p=401</guid>
		<description><![CDATA[In the previous post I showed You how to create custom log in page for forms authentication. Now I&#8217;ll explain how to manage roles from the code side. The main class which lets You manage roles from provider is System.Web.Security.SqlRoleProvider class. To get the SqlRoleProvider object You have to use System.Web.Security.Roles class and pass the [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://tomaszrabinski.pl/wordpress/wp-content/uploads/2011/06/RolesProvider.png"><img class="alignleft size-full wp-image-404" style="margin-right: 10px; maegin bottom: 5px;" title="RolesProvider" src="http://tomaszrabinski.pl/wordpress/wp-content/uploads/2011/06/RolesProvider.png" alt="" width="139" height="123" /></a>In the previous post I showed You how to create custom log in page for forms authentication. Now I&#8217;ll explain how to manage roles from the code side.</p>
<p>The main class which lets You manage roles from provider is <a href="http://msdn.microsoft.com/en-us/library/system.web.security.sqlroleprovider%28v=VS.90%29.aspx" target="_blank">System.Web.Security.SqlRoleProvider</a> class.</p>
<p>To get the SqlRoleProvider object You have to use <a href="http://msdn.microsoft.com/en-us/library/system.web.security.roles%28v=VS.90%29.aspx" target="_blank">System.Web.Security.Roles</a> class and pass the name of the provider You want to obtain:<span id="more-401"></span></p>
<pre class="brush: csharp; title: ; notranslate">

SqlRoleProvider provider = Roles.Providers[&quot;ProviderName&quot;] as SqlRoleProvider;
</pre>
<p>To get the names of all existing roles in the provider:</p>
<pre class="brush: csharp; title: ; notranslate">

string[] roleNames = provider.GetAllRoles();
</pre>
<p>To add a new role:</p>
<pre class="brush: csharp; title: ; notranslate">

provider.CreateRole(&quot;RoleName&quot;);
</pre>
<p>To delete role:</p>
<pre class="brush: csharp; title: ; notranslate">

provider.DeleteRole(&quot;RoleName&quot;);
</pre>
<p>To add a user to the role:</p>
<pre class="brush: csharp; title: ; notranslate">

provider.AddUsersToRoles(new string[] { &quot;UserName&quot; }, new string[] { &quot;RoleName&quot; });
</pre>
<p>To get a list of all users in the role:</p>
<pre class="brush: csharp; title: ; notranslate">

string[] users = provider.GetUsersInRole(&quot;RoleName&quot;);
</pre>
<p>To remove users from the role:</p>
<pre class="brush: csharp; title: ; notranslate">

provider.RemoveUsersFromRoles(new string[] { &quot;UserName&quot; }, new string[] { &quot;RoleName&quot; });
</pre>
]]></content:encoded>
			<wfw:commentRss>http://tomaszrabinski.pl/wordpress/2011/06/23/sqlmembershipprovider-roles-management/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://tomaszrabinski.pl/wordpress/2011/06/23/sqlmembershipprovider-roles-management/</feedburner:origLink></item>
	</channel>
</rss>

