<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Httpcode</title>
    <link>http://httpcode.com/blogs/</link>
    <description />
    <language>en-us</language>
    <copyright>Daniel Pollard</copyright>
    <lastBuildDate>Tue, 16 Mar 2010 21:45:00 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.1.8102.813</generator>
    <managingEditor>webiste@httpcode.com</managingEditor>
    <webMaster>webiste@httpcode.com</webMaster>
    <item>
      <trackback:ping>http://httpcode.com/blogs/Trackback.aspx?guid=7f5765bf-af6c-4da2-9e7c-70f905875751</trackback:ping>
      <pingback:server>http://httpcode.com/blogs/pingback.aspx</pingback:server>
      <pingback:target>http://httpcode.com/blogs/PermaLink,guid,7f5765bf-af6c-4da2-9e7c-70f905875751.aspx</pingback:target>
      <dc:creator>Daniel Pollard</dc:creator>
      <wfw:comment>http://httpcode.com/blogs/CommentView,guid,7f5765bf-af6c-4da2-9e7c-70f905875751.aspx</wfw:comment>
      <wfw:commentRss>http://httpcode.com/blogs/SyndicationService.asmx/GetEntryCommentsRss?guid=7f5765bf-af6c-4da2-9e7c-70f905875751</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I recently looked at some code that pulled a bunch of news items from a SharePoint
list and displayed them in random order. The code was a little verbose, so I changed
it to use the System.Data.DataSetExtension helper methods. The final code looked something
like this:
</p>
        <blockquote>
          <pre class="brush: c-sharp;"> 

//Perform the normal SPQuery
SPQuery query = new SPQuery();

// query options left for reader to insert
//the list variable is a reference to the SharePoint list you want to query
DataTable data = list.GetItems(query).GetDataTable();

Random rnd = new Random();

//Randomize the items using LINQ and some helper methods from System.Data.DataSetExtension
DataTable items = data.AsEnumerable().OrderBy((i) =&gt; (r.Next()));



</pre>
        </blockquote>
        <p>
The other nice thing about using the Random class is its flexibility to offer some
other cool features. Just say you wanted to show the same random items all day, then
it’s just a matter of seeding with the current day.
</p>
        <img width="0" height="0" src="http://httpcode.com/blogs/aggbug.ashx?id=7f5765bf-af6c-4da2-9e7c-70f905875751" />
      </body>
      <title>Random List Items using LINQ</title>
      <guid isPermaLink="false">http://httpcode.com/blogs/PermaLink,guid,7f5765bf-af6c-4da2-9e7c-70f905875751.aspx</guid>
      <link>http://httpcode.com/blogs/PermaLink,guid,7f5765bf-af6c-4da2-9e7c-70f905875751.aspx</link>
      <pubDate>Tue, 16 Mar 2010 21:45:00 GMT</pubDate>
      <description>&lt;p&gt;
I recently looked at some code that pulled a bunch of news items from a SharePoint
list and displayed them in random order. The code was a little verbose, so I changed
it to use the System.Data.DataSetExtension helper methods. The final code looked something
like this:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre class="brush: c-sharp;"&gt; 

//Perform the normal SPQuery
SPQuery query = new SPQuery();

// query options left for reader to insert
//the list variable is a reference to the SharePoint list you want to query
DataTable data = list.GetItems(query).GetDataTable();

Random rnd = new Random();

//Randomize the items using LINQ and some helper methods from System.Data.DataSetExtension
DataTable items = data.AsEnumerable().OrderBy((i) =&amp;gt; (r.Next()));



&lt;/pre&gt;&lt;/blockquote&gt; 
&lt;p&gt;
The other nice thing about using the Random class is its flexibility to offer some
other cool features. Just say you wanted to show the same random items all day, then
it’s just a matter of seeding with the current day.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://httpcode.com/blogs/aggbug.ashx?id=7f5765bf-af6c-4da2-9e7c-70f905875751" /&gt;</description>
      <comments>http://httpcode.com/blogs/CommentView,guid,7f5765bf-af6c-4da2-9e7c-70f905875751.aspx</comments>
      <category>code</category>
      <category>Sharepoint</category>
    </item>
    <item>
      <trackback:ping>http://httpcode.com/blogs/Trackback.aspx?guid=8b267ee2-e214-4187-8e8d-e3c4f092fc66</trackback:ping>
      <pingback:server>http://httpcode.com/blogs/pingback.aspx</pingback:server>
      <pingback:target>http://httpcode.com/blogs/PermaLink,guid,8b267ee2-e214-4187-8e8d-e3c4f092fc66.aspx</pingback:target>
      <dc:creator>Daniel Pollard</dc:creator>
      <wfw:comment>http://httpcode.com/blogs/CommentView,guid,8b267ee2-e214-4187-8e8d-e3c4f092fc66.aspx</wfw:comment>
      <wfw:commentRss>http://httpcode.com/blogs/SyndicationService.asmx/GetEntryCommentsRss?guid=8b267ee2-e214-4187-8e8d-e3c4f092fc66</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <title>Building a SharePoint 2010 tag cloud search refiner</title>
      <guid isPermaLink="false">http://httpcode.com/blogs/PermaLink,guid,8b267ee2-e214-4187-8e8d-e3c4f092fc66.aspx</guid>
      <link>http://httpcode.com/blogs/PermaLink,guid,8b267ee2-e214-4187-8e8d-e3c4f092fc66.aspx</link>
      <pubDate>Wed, 24 Feb 2010 09:46:00 GMT</pubDate>
      <description>&lt;p&gt;
One of the nice things about SharePoint 2010 is that the developers did not seal the
classes of the common web parts, so we can now create our own web parts that derive
and extent the functionality. I thought it might be fun to play with the search refiner
web part that I blogged about &lt;a href="http://httpcode.com/blogs/PermaLink,guid,935719ed-8d5d-4206-b7e9-de1c2dd72f65.aspx"&gt;recently&lt;/a&gt;,
so I took the standard search refiner and plugged in the excellent &lt;a href="http://thetagcloud.codeplex.com/"&gt;tag
cloud&lt;/a&gt; implementation from &lt;a href="http://www.codeplex.com/"&gt;codeplex&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
So instead of rendering the normal list of refiners with counts against them, it instead
uses the count to determine the tag cloud size:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/BuildingaSharePoint2010tagcloudsearchref_5C40/VisualTagCloudRefiner_2.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="VisualTagCloudRefiner" border="0" alt="VisualTagCloudRefiner" src="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/BuildingaSharePoint2010tagcloudsearchref_5C40/VisualTagCloudRefiner_thumb.png" width="231" height="365"&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
The code for creating this is below:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre class="brush: c-sharp;"&gt;

public class VisualRefiner : Microsoft.Office.Server.Search.WebControls.RefinementWebPart
    {
        protected override void Render(System.Web.UI.HtmlTextWriter writer)
        {
            var xmlDoc = this._RefinementManager.GetRefinementXml();

            var filters = xmlDoc.GetElementsByTagName("Filter");

            Dictionary&lt;string , int&gt;
tags = new Dictionary&lt;string , int&gt;
(); foreach (XmlNode filter in filters) { var valueNode = filter.SelectSingleNode("Value");
var countNode = filter.SelectSingleNode("Count"); if (countNode != null &amp;amp;&amp;amp;
valueNode != null) { if (!string.IsNullOrEmpty(countNode.InnerText)) { int tagCount;
if (int.TryParse(countNode.InnerText, out tagCount)) { if (!tags.ContainsKey(valueNode.InnerText))
{ tags.Add(valueNode.InnerText, tagCount); } } } } } //TODO: Make the url useable
var tagCloud = new TagCloud(tags, new TagCloudGenerationRules { Order = TagCloudOrder.Random,
TagUrlFormatString = "/pages/search.aspx" }); writer.Write(tagCloud); } } 
&lt;/pre&gt;&lt;/blockquote&gt; 
&lt;p&gt;
I’m not saying that this view adds any more value than the standard refiner view,
in the screenshot above it actually looks pretty poor.
&lt;/p&gt;
&lt;p&gt;
The interesting part about the web part is the use of the refinement manager, it returns
the results of the refinement process in xml form. This is really powerful, it means
that we could potentially create some really creative visuals around the search results.
It will be interesting to watch the community to see what types of variations come
out.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://httpcode.com/blogs/aggbug.ashx?id=8b267ee2-e214-4187-8e8d-e3c4f092fc66" /&gt;</description>
      <comments>http://httpcode.com/blogs/CommentView,guid,8b267ee2-e214-4187-8e8d-e3c4f092fc66.aspx</comments>
      <category>code</category>
      <category>SharePoint 2010</category>
    </item>
    <item>
      <trackback:ping>http://httpcode.com/blogs/Trackback.aspx?guid=25e758cd-bdcc-4bfd-972c-af0fb7497c44</trackback:ping>
      <pingback:server>http://httpcode.com/blogs/pingback.aspx</pingback:server>
      <pingback:target>http://httpcode.com/blogs/PermaLink,guid,25e758cd-bdcc-4bfd-972c-af0fb7497c44.aspx</pingback:target>
      <dc:creator>Daniel Pollard</dc:creator>
      <wfw:comment>http://httpcode.com/blogs/CommentView,guid,25e758cd-bdcc-4bfd-972c-af0fb7497c44.aspx</wfw:comment>
      <wfw:commentRss>http://httpcode.com/blogs/SyndicationService.asmx/GetEntryCommentsRss?guid=25e758cd-bdcc-4bfd-972c-af0fb7497c44</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
If you’ve ever built a custom protocol handler for MOSS before you may have in the
past used the object model to create the content source, since there is no way in
Central Admin to do this.
</p>
        <p>
 
</p>
        <p>
Something like:
</p>
        <p>
 
</p>
        <pre class="csharpcode">SearchContext context = SearchContext.GetCurrent(spSite);

Content content = <span class="kwrd">new</span> Content(context);
CustomContentSource source = (CustomContentSource)content.ContentSources.Create( ...</pre>
        <pre class="csharpcode">source.Update();</pre>
        <p>
          <style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
        </p>
        <p>
But the SearchContext in SharePoint 2010 is marked as obsolete, which makes total
sense when you consider that the SSP is no more, it’s been replaced by service applications.
</p>
        <p>
 
</p>
        <p>
The good news is that we can use Powershell to create the custom content source:
</p>
        <p>
 
</p>
        <p>
&gt; $sapp = Get-SPEnterpriseSearchServiceApplication –Identity “Search Service Application”
</p>
        <p>
&gt;New-SPEnterpriseSearchCrawlContentSource –SearchApplication $sapp –Name “Custom
Source Name” –Type Custom –StartAddress  protocol://servername –CrawlPriority
Normal –MaxPageEnumerationDepth 1 –MaxSiteEnumerationDepth 1
</p>
        <p>
 
</p>
        <p>
 
</p>
        <p>
So much easier …
</p>
        <p>
 
</p>
        <p>
Also when you register your custom protocol handler for SharePoint 2010, remember
that the registry hive location now has the number ‘14.0’ in its path:
</p>
        <p>
 
</p>
        <p>
HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Office  Server/14.0/Search/Setup/ProtocolHandlers
</p>
        <p>
 
</p>
        <p>
I still need to have a good play the new BCS stuff in SharePoint 2010, but looking
at this <a href="http://www.toddbaginski.com/blog/archive/2009/11/05/how-to-create-a-searchable-sharepoint-2010-bdc-.net-assembly-connector-which-reads-from-a-flat-file.aspx">post</a> by <a href="http://www.toddbaginski.com/blog/Default.aspx">Todd
Baginski</a> I have a feeling that we might have a few more tricks up our sleeves
before we go down the custom protocol handler or FAST pipeline route.
</p>
        <img width="0" height="0" src="http://httpcode.com/blogs/aggbug.ashx?id=25e758cd-bdcc-4bfd-972c-af0fb7497c44" />
      </body>
      <title>SharePoint 2010 – Installing a custom content source</title>
      <guid isPermaLink="false">http://httpcode.com/blogs/PermaLink,guid,25e758cd-bdcc-4bfd-972c-af0fb7497c44.aspx</guid>
      <link>http://httpcode.com/blogs/PermaLink,guid,25e758cd-bdcc-4bfd-972c-af0fb7497c44.aspx</link>
      <pubDate>Fri, 19 Feb 2010 23:36:00 GMT</pubDate>
      <description>&lt;p&gt;
If you’ve ever built a custom protocol handler for MOSS before you may have in the
past used the object model to create the content source, since there is no way in
Central Admin to do this.
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Something like:
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;SearchContext context = SearchContext.GetCurrent(spSite);

Content content = &lt;span class="kwrd"&gt;new&lt;/span&gt; Content(context);
CustomContentSource source = (CustomContentSource)content.ContentSources.Create( ...&lt;/pre&gt;&lt;pre class="csharpcode"&gt;source.Update();&lt;/pre&gt;
&lt;p&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;/p&gt;
&lt;p&gt;
But the SearchContext in SharePoint 2010 is marked as obsolete, which makes total
sense when you consider that the SSP is no more, it’s been replaced by service applications.
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
The good news is that we can use Powershell to create the custom content source:
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&amp;gt; $sapp = Get-SPEnterpriseSearchServiceApplication –Identity “Search Service Application”
&lt;/p&gt;
&lt;p&gt;
&amp;gt;New-SPEnterpriseSearchCrawlContentSource –SearchApplication $sapp –Name “Custom
Source Name” –Type Custom –StartAddress&amp;nbsp; protocol://servername –CrawlPriority
Normal –MaxPageEnumerationDepth 1 –MaxSiteEnumerationDepth 1
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
So much easier …
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Also when you register your custom protocol handler for SharePoint 2010, remember
that the registry hive location now has the number ‘14.0’ in its path:
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Office&amp;nbsp; Server/14.0/Search/Setup/ProtocolHandlers
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
I still need to have a good play the new BCS stuff in SharePoint 2010, but looking
at this &lt;a href="http://www.toddbaginski.com/blog/archive/2009/11/05/how-to-create-a-searchable-sharepoint-2010-bdc-.net-assembly-connector-which-reads-from-a-flat-file.aspx"&gt;post&lt;/a&gt; by &lt;a href="http://www.toddbaginski.com/blog/Default.aspx"&gt;Todd
Baginski&lt;/a&gt; I have a feeling that we might have a few more tricks up our sleeves
before we go down the custom protocol handler or FAST pipeline route.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://httpcode.com/blogs/aggbug.ashx?id=25e758cd-bdcc-4bfd-972c-af0fb7497c44" /&gt;</description>
      <comments>http://httpcode.com/blogs/CommentView,guid,25e758cd-bdcc-4bfd-972c-af0fb7497c44.aspx</comments>
      <category>Search</category>
      <category>SharePoint 2010</category>
    </item>
    <item>
      <trackback:ping>http://httpcode.com/blogs/Trackback.aspx?guid=935719ed-8d5d-4206-b7e9-de1c2dd72f65</trackback:ping>
      <pingback:server>http://httpcode.com/blogs/pingback.aspx</pingback:server>
      <pingback:target>http://httpcode.com/blogs/PermaLink,guid,935719ed-8d5d-4206-b7e9-de1c2dd72f65.aspx</pingback:target>
      <dc:creator>Daniel Pollard</dc:creator>
      <wfw:comment>http://httpcode.com/blogs/CommentView,guid,935719ed-8d5d-4206-b7e9-de1c2dd72f65.aspx</wfw:comment>
      <wfw:commentRss>http://httpcode.com/blogs/SyndicationService.asmx/GetEntryCommentsRss?guid=935719ed-8d5d-4206-b7e9-de1c2dd72f65</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
In MOSS 2007 we could use the <a href="http://www.codeplex.com/">codeplex</a><a href="http://www.codeplex.com/FacetedSearch">faceted
search</a> solution to provide what is now called ‘Search Refiners’ in SharePoint
2010.
</p>
        <p>
 
</p>
        <p>
By default the standard refiner will look like this:
</p>
        <p>
 
</p>
        <p>
          <a href="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/SharePoint2010Showingtheitemcountonthese_11EC7/image_2.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/SharePoint2010Showingtheitemcountonthese_11EC7/image_thumb.png" width="193" height="167" />
          </a>
        </p>
        <p>
 
</p>
        <p>
The really nice thing about the refiner is that it will only show a value if a search
result is returned for it, so a user will never be faced with clicking on an option
and have it return zero results.
</p>
        <p>
But those of us who are familiar with the old faceted search solution will know that
the web part displays a count of the results, well the SharePoint 2010 refiner can
as well:
</p>
        <p>
 
</p>
        <p>
          <a href="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/SharePoint2010Showingtheitemcountonthese_11EC7/image_4.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/SharePoint2010Showingtheitemcountonthese_11EC7/image_thumb_1.png" width="191" height="159" />
          </a>
        </p>
        <p>
Notice the subtle counts next to the metadata property.
</p>
        <p>
 
</p>
        <p>
This can be achieved by adding the following XML attribute to the refiners configuration
xml:
</p>
        <p>
 
</p>
        <p>
Find the &lt;Category&gt;  element that you wish to display counts for and add:  
ShowCounts=”Count”
</p>
        <img width="0" height="0" src="http://httpcode.com/blogs/aggbug.ashx?id=935719ed-8d5d-4206-b7e9-de1c2dd72f65" />
      </body>
      <title>SharePoint 2010 – Showing the item count on the search refiner</title>
      <guid isPermaLink="false">http://httpcode.com/blogs/PermaLink,guid,935719ed-8d5d-4206-b7e9-de1c2dd72f65.aspx</guid>
      <link>http://httpcode.com/blogs/PermaLink,guid,935719ed-8d5d-4206-b7e9-de1c2dd72f65.aspx</link>
      <pubDate>Fri, 19 Feb 2010 23:21:00 GMT</pubDate>
      <description>&lt;p&gt;
In MOSS 2007 we could use the &lt;a href="http://www.codeplex.com/"&gt;codeplex&lt;/a&gt; &lt;a href="http://www.codeplex.com/FacetedSearch"&gt;faceted
search&lt;/a&gt; solution to provide what is now called ‘Search Refiners’ in SharePoint
2010.
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
By default the standard refiner will look like this:
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/SharePoint2010Showingtheitemcountonthese_11EC7/image_2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/SharePoint2010Showingtheitemcountonthese_11EC7/image_thumb.png" width="193" height="167"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
The really nice thing about the refiner is that it will only show a value if a search
result is returned for it, so a user will never be faced with clicking on an option
and have it return zero results.
&lt;/p&gt;
&lt;p&gt;
But those of us who are familiar with the old faceted search solution will know that
the web part displays a count of the results, well the SharePoint 2010 refiner can
as well:
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/SharePoint2010Showingtheitemcountonthese_11EC7/image_4.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/SharePoint2010Showingtheitemcountonthese_11EC7/image_thumb_1.png" width="191" height="159"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
Notice the subtle counts next to the metadata property.
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
This can be achieved by adding the following XML attribute to the refiners configuration
xml:
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Find the &amp;lt;Category&amp;gt;&amp;nbsp; element that you wish to display counts for and add:&amp;nbsp;&amp;nbsp;
ShowCounts=”Count”
&lt;/p&gt;
&lt;img width="0" height="0" src="http://httpcode.com/blogs/aggbug.ashx?id=935719ed-8d5d-4206-b7e9-de1c2dd72f65" /&gt;</description>
      <comments>http://httpcode.com/blogs/CommentView,guid,935719ed-8d5d-4206-b7e9-de1c2dd72f65.aspx</comments>
      <category>Search</category>
      <category>SharePoint 2010</category>
    </item>
    <item>
      <trackback:ping>http://httpcode.com/blogs/Trackback.aspx?guid=b3af80e2-4e6f-41d6-ae93-61950a332a39</trackback:ping>
      <pingback:server>http://httpcode.com/blogs/pingback.aspx</pingback:server>
      <pingback:target>http://httpcode.com/blogs/PermaLink,guid,b3af80e2-4e6f-41d6-ae93-61950a332a39.aspx</pingback:target>
      <dc:creator>Daniel Pollard</dc:creator>
      <wfw:comment>http://httpcode.com/blogs/CommentView,guid,b3af80e2-4e6f-41d6-ae93-61950a332a39.aspx</wfw:comment>
      <wfw:commentRss>http://httpcode.com/blogs/SyndicationService.asmx/GetEntryCommentsRss?guid=b3af80e2-4e6f-41d6-ae93-61950a332a39</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <title>SharePoint 2010 Activity Feed – Enterprise Twitter</title>
      <guid isPermaLink="false">http://httpcode.com/blogs/PermaLink,guid,b3af80e2-4e6f-41d6-ae93-61950a332a39.aspx</guid>
      <link>http://httpcode.com/blogs/PermaLink,guid,b3af80e2-4e6f-41d6-ae93-61950a332a39.aspx</link>
      <pubDate>Sun, 22 Nov 2009 18:24:00 GMT</pubDate>
      <description>&lt;p&gt;
One of the more interesting features of SharePoint 2010 is the activity feed, it’s
kind of like the news feed in Facebook a whole range of system wide events are collated
in a users my site, these can include events generated by colleagues of a user. I
really think this is cool and we will see lots of applications make use of this feature.
Even in a business environment the concept of a status feed is useful, SharePoint
2010 provides what seems like a nice enterprise wide service for collecting these
events.
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
I thought it might be fun to have a play with some of the activity feed API’s to create
something like a Twitter web part for SharePoint 2010, just to be upfront, this code
isn’t really useable in a real sense, its just me playing around.
&lt;/p&gt;
&lt;p&gt;
First I’ve created a visual web part for the user to enter a tweet:
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/SharePoint2010ActivityFeedEnterpriseTwit_C269/image_2.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/SharePoint2010ActivityFeedEnterpriseTwit_C269/image_thumb.png" width="224" height="152"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Now if your a colleague, you can visit your ‘MySite’ and view the aggregated activities
of your colleagues:
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/SharePoint2010ActivityFeedEnterpriseTwit_C269/image_4.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/SharePoint2010ActivityFeedEnterpriseTwit_C269/image_thumb_1.png" width="408" height="201"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Here you can see that the user ‘administrator’ (this person’s colleague) has ‘tweeted’
something.
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
The SharePoint team have made this whole status/activity feed quite extensible, the
first step is to define your own activity application 
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Setup&lt;/strong&gt;:
&lt;/p&gt;
&lt;pre class="brush: c-sharp;"&gt;	private ActivityApplication actApplication = null;
	private ActivityManager actMgr = null;
	private UserProfile currentUserProfile = null;
	private ActivityType tweetActivityType = null;
	private ActivityTemplate tweetActTemplate = null;

	private void SetupActivities()
         {
            Microsoft.Office.Server.UserProfiles.UserProfileManager pm = new UserProfileManager(SPServiceContext.Current);
            currentUserProfile = pm.GetUserProfile(Page.User.Identity.Name);
            actMgr = new ActivityManager(currentUserProfile);
            tweetActivityType = null;

            if (actMgr.PrepareToAllowSchemaChanges())
            {
                if (actMgr.ActivityApplications["SP2010Twitter"] == null)
                {

                    actApplication = actMgr.ActivityApplications.Create("SP2010Twitter");
                    actApplication.Commit();
                }
                else
                {
                    actApplication = actMgr.ActivityApplications["SP2010Twitter"];
                }

                tweetActivityType = actApplication.ActivityTypes["SP2010Tweeting"];
                if (tweetActivityType == null)
                {
                    tweetActivityType = actApplication.ActivityTypes.Create("SP2010Tweeting");
                    tweetActivityType.ActivityTypeNameLocStringName = "ActivityName";
                    tweetActivityType.ActivityTypeNameLocStringResourceFile = "SP2010Twitter";
                    tweetActivityType.IsPublished = true;
                    tweetActivityType.IsConsolidated = true;
                    tweetActivityType.AllowRollup = true;
                    tweetActivityType.Commit();
                }

                tweetActTemplate = tweetActivityType.ActivityTemplates[ActivityTemplatesCollection.CreateKey(false)];
                if (tweetActTemplate == null)
                {
                    tweetActTemplate = tweetActivityType.ActivityTemplates.Create(false);
                    tweetActTemplate.TitleFormatLocStringResourceFile = "SP2010Twitter";
                    tweetActTemplate.TitleFormatLocStringName = "Activity_Created";
                    tweetActTemplate.Commit();
                }
            }
            else
            {
                //not a profile admin

                var activities = actMgr.GetActivitiesForMe();
                foreach (var act in activities)
                {
                    if (act.Name == "SP2010Twitter")
                    {
                        actID = act.ActivityTypeId;
                    }
                }
            }
            
            

        }
&lt;/pre&gt;
&lt;p&gt;
The code above needs to be run once, to setup the application and to define the templates
etc.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Creating an event&lt;/strong&gt;:
&lt;/p&gt;
&lt;pre class="brush: c-sharp;"&gt;	public ActivityEvent GenerateActivityEvent(string tweet, long activityId)
	{
            Entity owner = new MinimalPerson(CurrentUserProfile).CreateEntity(ActManager);
            Entity publisher = new MinimalPerson(CurrentUserProfile).CreateEntity(ActManager);
            
            ActivityEvent activityEvent = ActivityEvent.CreateActivityEvent(ActManager, activityId, owner, publisher);
            activityEvent.Name = "SP2010Twitter";
            activityEvent.ItemPrivacy = (int)Privacy.Public;
            activityEvent.Owner = owner;
            activityEvent.Publisher = publisher;            
            
            activityEvent.Value = tweet;
            activityEvent.Commit();

            
            return activityEvent;
        }

&lt;/pre&gt;
&lt;p&gt;
&lt;strong&gt;Publishing the event&lt;/strong&gt; to the user's colleagues:
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;pre class="brush: c-sharp;"&gt;	public void MulticastPublishedEvents()
	{
            if (activityEvents.Count == 0)
                return;

            List&lt;long&gt;
publishers = new List&lt;long&gt;
(); foreach (ActivityEvent activityEvent in activityEvents) { if (!publishers.Contains(activityEvent.Owner.Id))
publishers.Add(activityEvent.Owner.Id); } Dictionary&lt;long  , minimalperson&gt;
owners; Dictionary&lt;long  , List&gt;
&lt;minimalperson&gt;
&amp;gt; colleaguesOfOwners; ActivityFeedGatherer.GetUsersColleaguesAndRights(ActManager,
publishers, out owners, out colleaguesOfOwners); Dictionary&lt;long  , List&gt;
&lt;activityevent&gt;
&amp;gt; eventsPerOwner; ActivityFeedGatherer.MulticastActivityEvents(ActManager, activityEvents,
colleaguesOfOwners, out eventsPerOwner); List&lt;activityevent&gt;
eventsToMulticast; ActivityFeedGatherer.CollectActivityEventsToConsolidate(eventsPerOwner,
out eventsToMulticast); WriteEvents(eventsToMulticast); } private void WriteEvents(List&lt;activityevent&gt;
events) { int startIndex = 0; while (startIndex + ActManager.MaxEventsPerBatch &amp;lt;
events.Count) { ActivityFeedGatherer.BatchWriteActivityEvents(events, startIndex,
ActManager.MaxEventsPerBatch); startIndex += ActManager.MaxEventsPerBatch; } ActivityFeedGatherer.BatchWriteActivityEvents(events,
startIndex, events.Count - startIndex); } 
&lt;/pre&gt;
&lt;p&gt;
Publishing an event is a little more involved and this code was drawn heavily from
the SDK sample found &lt;a href="http://code.msdn.microsoft.com/activityfeedsconsole"&gt;here&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
The main classes that get used here are:
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.office.server.activityfeed.activityapplication(office.14).aspx"&gt;ActivityApplication&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
An activity application is simply the name of the application, the ‘NewsFeed Settings’
on the my site gives the end user the ability to participate with your application:
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;&lt;a href="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/SharePoint2010ActivityFeedEnterpriseTwit_C269/image_8.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/SharePoint2010ActivityFeedEnterpriseTwit_C269/image_thumb_3.png" width="342" height="401"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.office.server.activityfeed.activitymanager(office.14).aspx"&gt;ActivityManager&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
Simple manager class that gets initialised with the current user profile, this class
gets passed around to the other classes that create events.
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.office.server.activityfeed.activitytype(office.14).aspx"&gt;ActivityType&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
This class provides us with the ability to actually define the activity, things like
the time to live, is rolled up? and the template to use. This class also requires
the developer to define the resources file that will be used to display the activity
name.
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.office.server.activityfeed.activitytemplate(office.14).aspx"&gt;ActivityTemplate&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
The display of the activity event gets managed by this class, you need to specify
a resources file and key that contains the elements to create the display text. This
class and associated resources file controls the UI presented to the user.
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.office.server.activityfeed.activityevent(office.14).aspx"&gt;ActivityEvent&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
This is the actual event, here we define the publisher and other things like the item
privacy level, it’s possible to create public and private events.
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.office.server.activityfeed.activityfeedgatherer(office.14).aspx"&gt;ActivityFeedGatherer&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
The gatherer is probably the least intuitive class, it provides the ability to batch
write the events, this is handy because often we will want to publish the events to
all of the colleagues of the current user. 
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Resources File:&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
Like I mentioned above, all of the templates and UI elements must be in a resx file.
This file must be deployed to:
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
{SharePointRoot}\Resources\SP2010Twitter.resx
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
And will contain something like (note how the ActivityName and Activity_Created are
used in the code above):
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;data&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="ActivityName"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;xml:space&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="preserve"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;SP2010Twitter&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;data&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;data&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="Activity_Created"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;xml:space&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="preserve"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;{Publisher}
tweeted: {Value}&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;data&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Some of the &lt;strong&gt;Default Template Variables&lt;/strong&gt;:
&lt;/p&gt;
&lt;p&gt;
{Link}
&lt;/p&gt;
&lt;p&gt;
{Value}
&lt;/p&gt;
&lt;p&gt;
{Publisher}
&lt;/p&gt;
&lt;p&gt;
{Size}
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
So above I made use of the {Value} variable and populated the value property of the
event object with the tweet value. I could change the resx definition which would
change the way the event is shown to the user. 
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Problems:&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
I’ve come across a few little problems, firstly it seems like the user creating the
event needs to be a profile admin, even a call to ActivityEvent.CreateActivityEvent
seems to require the profile admin property. Unless I’m missing something, I hope
this changes in the RTM environment.
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
You can download the sample code &lt;a href="http://httpcode.com/ftp/SP2010Twitter.zip"&gt;here&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://httpcode.com/blogs/aggbug.ashx?id=b3af80e2-4e6f-41d6-ae93-61950a332a39" /&gt;</description>
      <comments>http://httpcode.com/blogs/CommentView,guid,b3af80e2-4e6f-41d6-ae93-61950a332a39.aspx</comments>
      <category>code</category>
      <category>SharePoint 2010</category>
    </item>
    <item>
      <trackback:ping>http://httpcode.com/blogs/Trackback.aspx?guid=989f6b75-265c-48b6-aed9-ef9326a3b382</trackback:ping>
      <pingback:server>http://httpcode.com/blogs/pingback.aspx</pingback:server>
      <pingback:target>http://httpcode.com/blogs/PermaLink,guid,989f6b75-265c-48b6-aed9-ef9326a3b382.aspx</pingback:target>
      <dc:creator>Daniel Pollard</dc:creator>
      <wfw:comment>http://httpcode.com/blogs/CommentView,guid,989f6b75-265c-48b6-aed9-ef9326a3b382.aspx</wfw:comment>
      <wfw:commentRss>http://httpcode.com/blogs/SyndicationService.asmx/GetEntryCommentsRss?guid=989f6b75-265c-48b6-aed9-ef9326a3b382</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I’ve been playing around with the new document set feature of SharePoint 2010, the
idea is that you can group a bunch of documents or digital assets and control the
metadata for all of them in one location.
</p>
        <p>
When I first saw the demo around the document sets it reminded me of a piece of work
I did for a client, they had a legacy system which would group a number of digital
assets into a single entity and the search would return this one single entity if
the search keyword was found in any of the documents. At the time we came to the conclusion
that MOSS wasn’t a suitable replacement because of the way the search subsystem worked.
Even with a custom protocol handler applying the correct metadata to each document/asset,
at the point you start trying to invoke the various IFilters (doc, pdf, ppt etc) to
index the contents of the documents you needed hand off a discrete url with the file
extension of the document (the IFilters are invoked based on the  url), what
would result was a disjointed search experience because the documents would be displayed
outside of the set.
</p>
        <p>
 
</p>
        <p>
A document set is displayed in the document library as a single entity:
</p>
        <p>
 
</p>
        <p>
          <a href="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/SharePoint2010DocumentSets_B26E/DocSet_2.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="DocSet" border="0" alt="DocSet" src="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/SharePoint2010DocumentSets_B26E/DocSet_thumb.png" width="496" height="178" />
          </a>
        </p>
        <p>
 
</p>
        <p>
When you select the document set, the ribbon changes so you can manage it or you can
select the edit properties to manage the common meta-data:
</p>
        <p>
 
</p>
        <p>
          <a href="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/SharePoint2010DocumentSets_B26E/docset2_2.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="docset2" border="0" alt="docset2" src="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/SharePoint2010DocumentSets_B26E/docset2_thumb.png" width="403" height="268" />
          </a>
        </p>
        <p>
 
</p>
        <p>
The next thing to look at is the search experience, performing a search for a term
that is in one of the documents of the set returns:
</p>
        <p>
 
</p>
        <p>
          <a href="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/SharePoint2010DocumentSets_B26E/image_2.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/SharePoint2010DocumentSets_B26E/image_thumb.png" width="638" height="257" />
          </a>
        </p>
        <p>
 
</p>
        <p>
In this case I searched for a keyword that was specific to a document, the search
results returned a just the single document, <strong>no reference to a document set.</strong></p>
        <p>
 
</p>
        <p>
Searching for a keyword that is contained in both the document set and document returns:
</p>
        <p>
 
</p>
        <p>
          <a href="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/SharePoint2010DocumentSets_B26E/image_4.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/SharePoint2010DocumentSets_B26E/image_thumb_1.png" width="318" height="264" />
          </a>
        </p>
        <p>
 
</p>
        <p>
In this case we get the <strong>document set as a result</strong> and the document,
rather than just a document set, the user has no idea that the document (Internet
SharePoint Governance Plan) was apart of a document set.
</p>
        <p>
 
</p>
        <p>
          <strong>I’m not saying the document set feature is useless</strong>, I think it has
some valid scenario’s, I just would have liked it to work a little differently, but
I guess the SharePoint team hasn’t changed the search engine under the covers and
are constrained in the same way I was. I think the FAST pipeline offers some other
alternatives, but I haven’t had a chance to look at that yet.
</p>
        <img width="0" height="0" src="http://httpcode.com/blogs/aggbug.ashx?id=989f6b75-265c-48b6-aed9-ef9326a3b382" />
      </body>
      <title>SharePoint 2010 – Document Sets and Search Experience</title>
      <guid isPermaLink="false">http://httpcode.com/blogs/PermaLink,guid,989f6b75-265c-48b6-aed9-ef9326a3b382.aspx</guid>
      <link>http://httpcode.com/blogs/PermaLink,guid,989f6b75-265c-48b6-aed9-ef9326a3b382.aspx</link>
      <pubDate>Sun, 22 Nov 2009 10:02:00 GMT</pubDate>
      <description>&lt;p&gt;
I’ve been playing around with the new document set feature of SharePoint 2010, the
idea is that you can group a bunch of documents or digital assets and control the
metadata for all of them in one location.
&lt;/p&gt;
&lt;p&gt;
When I first saw the demo around the document sets it reminded me of a piece of work
I did for a client, they had a legacy system which would group a number of digital
assets into a single entity and the search would return this one single entity if
the search keyword was found in any of the documents. At the time we came to the conclusion
that MOSS wasn’t a suitable replacement because of the way the search subsystem worked.
Even with a custom protocol handler applying the correct metadata to each document/asset,
at the point you start trying to invoke the various IFilters (doc, pdf, ppt etc) to
index the contents of the documents you needed hand off a discrete url with the file
extension of the document (the IFilters are invoked based on the&amp;nbsp; url), what
would result was a disjointed search experience because the documents would be displayed
outside of the set.
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
A document set is displayed in the document library as a single entity:
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/SharePoint2010DocumentSets_B26E/DocSet_2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="DocSet" border="0" alt="DocSet" src="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/SharePoint2010DocumentSets_B26E/DocSet_thumb.png" width="496" height="178"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
When you select the document set, the ribbon changes so you can manage it or you can
select the edit properties to manage the common meta-data:
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/SharePoint2010DocumentSets_B26E/docset2_2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="docset2" border="0" alt="docset2" src="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/SharePoint2010DocumentSets_B26E/docset2_thumb.png" width="403" height="268"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
The next thing to look at is the search experience, performing a search for a term
that is in one of the documents of the set returns:
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/SharePoint2010DocumentSets_B26E/image_2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/SharePoint2010DocumentSets_B26E/image_thumb.png" width="638" height="257"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
In this case I searched for a keyword that was specific to a document, the search
results returned a just the single document, &lt;strong&gt;no reference to a document set.&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Searching for a keyword that is contained in both the document set and document returns:
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/SharePoint2010DocumentSets_B26E/image_4.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/SharePoint2010DocumentSets_B26E/image_thumb_1.png" width="318" height="264"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
In this case we get the &lt;strong&gt;document set as a result&lt;/strong&gt; and the document,
rather than just a document set, the user has no idea that the document (Internet
SharePoint Governance Plan) was apart of a document set.
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;I’m not saying the document set feature is useless&lt;/strong&gt;, I think it has
some valid scenario’s, I just would have liked it to work a little differently, but
I guess the SharePoint team hasn’t changed the search engine under the covers and
are constrained in the same way I was. I think the FAST pipeline offers some other
alternatives, but I haven’t had a chance to look at that yet.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://httpcode.com/blogs/aggbug.ashx?id=989f6b75-265c-48b6-aed9-ef9326a3b382" /&gt;</description>
      <comments>http://httpcode.com/blogs/CommentView,guid,989f6b75-265c-48b6-aed9-ef9326a3b382.aspx</comments>
      <category>SharePoint 2010</category>
    </item>
    <item>
      <trackback:ping>http://httpcode.com/blogs/Trackback.aspx?guid=357e4853-9a75-4962-ad68-1e07bcf40bb8</trackback:ping>
      <pingback:server>http://httpcode.com/blogs/pingback.aspx</pingback:server>
      <pingback:target>http://httpcode.com/blogs/PermaLink,guid,357e4853-9a75-4962-ad68-1e07bcf40bb8.aspx</pingback:target>
      <dc:creator>Daniel Pollard</dc:creator>
      <wfw:comment>http://httpcode.com/blogs/CommentView,guid,357e4853-9a75-4962-ad68-1e07bcf40bb8.aspx</wfw:comment>
      <wfw:commentRss>http://httpcode.com/blogs/SyndicationService.asmx/GetEntryCommentsRss?guid=357e4853-9a75-4962-ad68-1e07bcf40bb8</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Ever since the sneak peak developer videos were released months ago I’ve been wondering
about the implementation of SharePoint 2010’s visual web parts. If your not sure what
I mean, with SP 2010 and Visual Studio 2010 you can now create a web part with a design
time experience, so you can drag and drop controls etc:
</p>
        <p>
 
</p>
        <p>
          <a href="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/SharePoint2010VisualWebParts_10578/VS2010Designer_2.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="VS2010Designer" border="0" alt="VS2010Designer" src="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/SharePoint2010VisualWebParts_10578/VS2010Designer_thumb.png" width="555" height="226" />
          </a>
        </p>
        <p>
 
</p>
        <p>
Now that the beta is upon us I can finally take a look under the covers at a visual
web part, the default project structure looks like:
</p>
        <p>
          <a href="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/SharePoint2010VisualWebParts_10578/VS2010WebPart_2.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="VS2010WebPart" border="0" alt="VS2010WebPart" src="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/SharePoint2010VisualWebParts_10578/VS2010WebPart_thumb.png" width="279" height="261" />
          </a>
        </p>
        <p>
 
</p>
        <p>
The project contains a number of new items: Features and Package both relate to the
deployment features of Visual Studio 2010 in that you can create SharePoint solutions
(aka the Package) and features which can be activated, visual studio will automatically
deploy and activate your web parts using this solution and features.
</p>
        <p>
Next we move on to the VisualWebPart1.cs file which contains the <strong>secret sauce</strong>:
</p>
        <p>
 
</p>
        <pre class="csharpcode">
          <span class="kwrd">public</span>
          <span class="kwrd">class</span> VisualWebPart1
: WebPart { <span class="rem">// Visual Studio might automatically update this path
when you change the Visual Web Part project item.</span><span class="kwrd">private</span><span class="kwrd">const</span><span class="kwrd">string</span> _ascxPath
= <span class="str">@"~/_CONTROLTEMPLATES/TestVisualWebPart/VisualWebPart1/VisualWebPart1UserControl.ascx"</span>; <span class="kwrd">public</span> VisualWebPart1()
{ } <span class="kwrd">protected</span><span class="kwrd">override</span><span class="kwrd">void</span> CreateChildControls()
{ Control control = <span class="kwrd">this</span>.Page.LoadControl(_ascxPath); Controls.Add(control); <span class="kwrd">base</span>.CreateChildControls();
} <span class="kwrd">protected</span><span class="kwrd">override</span><span class="kwrd">void</span> RenderContents(HtmlTextWriter
writer) { <span class="kwrd">base</span>.RenderContents(writer); }</pre>
        <style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
        <p>
 
</p>
        <p>
As you can see, the web part still derives from WebPart, no special VisualWebPart
base class, nothing special going on here.
</p>
        <p>
In fact we are using the same techniques and approach that would have worked in Visual
Studio 2008, the only difference now is that <strong>Visual Studio 2010 has better
tooling support for SharePoint 2010 </strong>and will deploy the ascx file automatically
for us to the _CONTROLTEMPLATES directory as part of the solution<strong>.</strong>  
</p>
        <p>
 
</p>
        <p>
There are still a few things a web part developer should know, lets look at the case
where we want to expose some custom properties on a web part that we want a user to
configure via the web interface:
</p>
        <p>
 
</p>
        <pre class="csharpcode">      [System.Web.UI.WebControls.WebParts.WebBrowsable(<span class="kwrd">true</span>),
System.Web.UI.WebControls.WebParts.WebDisplayName(<span class="str">"Custom Prop"</span>),
System.Web.UI.WebControls.WebParts.WebDescription(<span class="str">""</span>), System.Web.UI.WebControls.WebParts.Personalizable(
System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared), System.ComponentModel.Category(<span class="str">"Settings"</span>),
System.ComponentModel.DefaultValue(<span class="str">""</span>) ] <span class="kwrd">public</span><span class="kwrd">string</span> CustomProp
{ get { <span class="kwrd">return</span> customProp; } set { customProp = <span class="kwrd">value</span>;
} }</pre>
        <style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
        <p>
 
</p>
        <p>
Now if we put this property and attributes on the VisualWebPart1UserControl (in VisualWebPart1UserControl.ascx.cs)
we will find that the custom property builder <strong>won’t appear</strong> (the web
interface that lets us set a value to this property).
</p>
        <p>
 
</p>
        <p>
We have to add the custom property on the VisualWebPart1 class (in VisualWebPart1.cs)
:
</p>
        <p>
 
</p>
        <pre class="csharpcode">
          <span class="kwrd">public</span>
          <span class="kwrd">class</span> VisualWebPart1
: WebPart { <span class="rem">// Visual Studio might automatically update this path
when you change the Visual Web Part project item.</span><span class="kwrd">private</span><span class="kwrd">const</span><span class="kwrd">string</span> _ascxPath
= <span class="str">@"~/_CONTROLTEMPLATES/TestVisualWebPart/VisualWebPart1/VisualWebPart1UserControl.ascx"</span>; <span class="kwrd">protected</span><span class="kwrd">override</span><span class="kwrd">void</span> CreateChildControls()
{ Control control = <span class="kwrd">this</span>.Page.LoadControl(_ascxPath); Controls.Add(control); <span class="kwrd">base</span>.CreateChildControls();
} <span class="kwrd">protected</span><span class="kwrd">override</span><span class="kwrd">void</span> RenderContents(HtmlTextWriter
writer) { <span class="kwrd">base</span>.RenderContents(writer); } [System.Web.UI.WebControls.WebParts.WebBrowsable(<span class="kwrd">true</span>),
System.Web.UI.WebControls.WebParts.WebDisplayName(<span class="str">"Custom Prop"</span>),
System.Web.UI.WebControls.WebParts.WebDescription(<span class="str">""</span>), System.Web.UI.WebControls.WebParts.Personalizable(
System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared), System.ComponentModel.Category(<span class="str">"Settings"</span>),
System.ComponentModel.DefaultValue(<span class="str">""</span>) ] <span class="kwrd">public</span><span class="kwrd">string</span> CustomProp
{ get { <span class="kwrd">return</span> customProp; } set { customProp = <span class="kwrd">value</span>;
} } }</pre>
        <style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
        <p>
Now we get our custom property builder:
</p>
        <p>
          <a href="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/SharePoint2010VisualWebParts_10578/WebPartSettings_2.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="WebPartSettings" border="0" alt="WebPartSettings" src="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/SharePoint2010VisualWebParts_10578/WebPartSettings_thumb.png" width="244" height="211" />
          </a>
        </p>
        <p>
 
</p>
        <p>
Lets assume that we want to pass the user entered value to the Visual component (the
usercontrol) we now need to change the visual studio generated code to cast the user
control to our visual user control class, rather than the more generic base Control: 
</p>
        <pre class="csharpcode">
          <span class="kwrd">protected</span>
          <span class="kwrd">override</span>
          <span class="kwrd">void</span> CreateChildControls()
{ <span class="rem">//user control is of type VisualWebPart1UserControl and defined
with private scope</span> userControl = (VisualWebPart1UserControl)<span class="kwrd">this</span>.Page.LoadControl(_ascxPath);
Controls.Add(control); <span class="kwrd">base</span>.CreateChildControls(); }</pre>
        <style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
        <p>
 
</p>
        <p>
From here we can set properties on the userControl variable as normal. 
</p>
        <p>
 
</p>
        <p>
The same principles apply to web part connections, so the connection points need to
be defined on the web part class (not the usercontrol). <strong>Visual Studio will
take care of deploying the ascx file </strong>which is still a big win.
</p>
        <p>
 
</p>
        <p>
I doubt an experienced web part developer would have any issues, but I wonder how
many new web part developers will not know that they can make there web parts configurable
and connectable given that they will likely only use the Visual Studio lie presented
to them?
</p>
        <img width="0" height="0" src="http://httpcode.com/blogs/aggbug.ashx?id=357e4853-9a75-4962-ad68-1e07bcf40bb8" />
      </body>
      <title>SharePoint 2010 Visual Web Parts</title>
      <guid isPermaLink="false">http://httpcode.com/blogs/PermaLink,guid,357e4853-9a75-4962-ad68-1e07bcf40bb8.aspx</guid>
      <link>http://httpcode.com/blogs/PermaLink,guid,357e4853-9a75-4962-ad68-1e07bcf40bb8.aspx</link>
      <pubDate>Wed, 18 Nov 2009 00:30:00 GMT</pubDate>
      <description>&lt;p&gt;
Ever since the sneak peak developer videos were released months ago I’ve been wondering
about the implementation of SharePoint 2010’s visual web parts. If your not sure what
I mean, with SP 2010 and Visual Studio 2010 you can now create a web part with a design
time experience, so you can drag and drop controls etc:
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/SharePoint2010VisualWebParts_10578/VS2010Designer_2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="VS2010Designer" border="0" alt="VS2010Designer" src="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/SharePoint2010VisualWebParts_10578/VS2010Designer_thumb.png" width="555" height="226"&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Now that the beta is upon us I can finally take a look under the covers at a visual
web part, the default project structure looks like:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/SharePoint2010VisualWebParts_10578/VS2010WebPart_2.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="VS2010WebPart" border="0" alt="VS2010WebPart" src="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/SharePoint2010VisualWebParts_10578/VS2010WebPart_thumb.png" width="279" height="261"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
The project contains a number of new items: Features and Package both relate to the
deployment features of Visual Studio 2010 in that you can create SharePoint solutions
(aka the Package) and features which can be activated, visual studio will automatically
deploy and activate your web parts using this solution and features.
&lt;/p&gt;
&lt;p&gt;
Next we move on to the VisualWebPart1.cs file which contains the &lt;strong&gt;secret sauce&lt;/strong&gt;:
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; VisualWebPart1
: WebPart { &lt;span class="rem"&gt;// Visual Studio might automatically update this path
when you change the Visual Web Part project item.&lt;/span&gt; &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;const&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; _ascxPath
= &lt;span class="str"&gt;@"~/_CONTROLTEMPLATES/TestVisualWebPart/VisualWebPart1/VisualWebPart1UserControl.ascx"&lt;/span&gt;; &lt;span class="kwrd"&gt;public&lt;/span&gt; VisualWebPart1()
{ } &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; CreateChildControls()
{ Control control = &lt;span class="kwrd"&gt;this&lt;/span&gt;.Page.LoadControl(_ascxPath); Controls.Add(control); &lt;span class="kwrd"&gt;base&lt;/span&gt;.CreateChildControls();
} &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; RenderContents(HtmlTextWriter
writer) { &lt;span class="kwrd"&gt;base&lt;/span&gt;.RenderContents(writer); }&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
As you can see, the web part still derives from WebPart, no special VisualWebPart
base class, nothing special going on here.
&lt;/p&gt;
&lt;p&gt;
In fact we are using the same techniques and approach that would have worked in Visual
Studio 2008, the only difference now is that &lt;strong&gt;Visual Studio 2010 has better
tooling support for SharePoint 2010 &lt;/strong&gt;and will deploy the ascx file automatically
for us to the _CONTROLTEMPLATES directory as part of the solution&lt;strong&gt;.&lt;/strong&gt;&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
There are still a few things a web part developer should know, lets look at the case
where we want to expose some custom properties on a web part that we want a user to
configure via the web interface:
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;      [System.Web.UI.WebControls.WebParts.WebBrowsable(&lt;span class="kwrd"&gt;true&lt;/span&gt;),
System.Web.UI.WebControls.WebParts.WebDisplayName(&lt;span class="str"&gt;"Custom Prop"&lt;/span&gt;),
System.Web.UI.WebControls.WebParts.WebDescription(&lt;span class="str"&gt;""&lt;/span&gt;), System.Web.UI.WebControls.WebParts.Personalizable(
System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared), System.ComponentModel.Category(&lt;span class="str"&gt;"Settings"&lt;/span&gt;),
System.ComponentModel.DefaultValue(&lt;span class="str"&gt;""&lt;/span&gt;) ] &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; CustomProp
{ get { &lt;span class="kwrd"&gt;return&lt;/span&gt; customProp; } set { customProp = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
} }&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Now if we put this property and attributes on the VisualWebPart1UserControl (in VisualWebPart1UserControl.ascx.cs)
we will find that the custom property builder &lt;strong&gt;won’t appear&lt;/strong&gt; (the web
interface that lets us set a value to this property).
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
We have to add the custom property on the VisualWebPart1 class (in VisualWebPart1.cs)
:
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; VisualWebPart1
: WebPart { &lt;span class="rem"&gt;// Visual Studio might automatically update this path
when you change the Visual Web Part project item.&lt;/span&gt; &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;const&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; _ascxPath
= &lt;span class="str"&gt;@"~/_CONTROLTEMPLATES/TestVisualWebPart/VisualWebPart1/VisualWebPart1UserControl.ascx"&lt;/span&gt;; &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; CreateChildControls()
{ Control control = &lt;span class="kwrd"&gt;this&lt;/span&gt;.Page.LoadControl(_ascxPath); Controls.Add(control); &lt;span class="kwrd"&gt;base&lt;/span&gt;.CreateChildControls();
} &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; RenderContents(HtmlTextWriter
writer) { &lt;span class="kwrd"&gt;base&lt;/span&gt;.RenderContents(writer); } [System.Web.UI.WebControls.WebParts.WebBrowsable(&lt;span class="kwrd"&gt;true&lt;/span&gt;),
System.Web.UI.WebControls.WebParts.WebDisplayName(&lt;span class="str"&gt;"Custom Prop"&lt;/span&gt;),
System.Web.UI.WebControls.WebParts.WebDescription(&lt;span class="str"&gt;""&lt;/span&gt;), System.Web.UI.WebControls.WebParts.Personalizable(
System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared), System.ComponentModel.Category(&lt;span class="str"&gt;"Settings"&lt;/span&gt;),
System.ComponentModel.DefaultValue(&lt;span class="str"&gt;""&lt;/span&gt;) ] &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; CustomProp
{ get { &lt;span class="kwrd"&gt;return&lt;/span&gt; customProp; } set { customProp = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
} } }&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;p&gt;
Now we get our custom property builder:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/SharePoint2010VisualWebParts_10578/WebPartSettings_2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="WebPartSettings" border="0" alt="WebPartSettings" src="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/SharePoint2010VisualWebParts_10578/WebPartSettings_thumb.png" width="244" height="211"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Lets assume that we want to pass the user entered value to the Visual component (the
usercontrol) we now need to change the visual studio generated code to cast the user
control to our visual user control class, rather than the more generic base Control: 
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;       &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; CreateChildControls()
{ &lt;span class="rem"&gt;//user control is of type VisualWebPart1UserControl and defined
with private scope&lt;/span&gt; userControl = (VisualWebPart1UserControl)&lt;span class="kwrd"&gt;this&lt;/span&gt;.Page.LoadControl(_ascxPath);
Controls.Add(control); &lt;span class="kwrd"&gt;base&lt;/span&gt;.CreateChildControls(); }&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
From here we can set properties on the userControl variable as normal. 
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
The same principles apply to web part connections, so the connection points need to
be defined on the web part class (not the usercontrol). &lt;strong&gt;Visual Studio will
take care of deploying the ascx file &lt;/strong&gt;which is still a big win.
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
I doubt an experienced web part developer would have any issues, but I wonder how
many new web part developers will not know that they can make there web parts configurable
and connectable given that they will likely only use the Visual Studio lie presented
to them?
&lt;/p&gt;
&lt;img width="0" height="0" src="http://httpcode.com/blogs/aggbug.ashx?id=357e4853-9a75-4962-ad68-1e07bcf40bb8" /&gt;</description>
      <comments>http://httpcode.com/blogs/CommentView,guid,357e4853-9a75-4962-ad68-1e07bcf40bb8.aspx</comments>
      <category>code</category>
      <category>SharePoint 2010</category>
    </item>
    <item>
      <trackback:ping>http://httpcode.com/blogs/Trackback.aspx?guid=8894d5e7-e518-4ab4-93be-0a5c90caf468</trackback:ping>
      <pingback:server>http://httpcode.com/blogs/pingback.aspx</pingback:server>
      <pingback:target>http://httpcode.com/blogs/PermaLink,guid,8894d5e7-e518-4ab4-93be-0a5c90caf468.aspx</pingback:target>
      <dc:creator>Daniel Pollard</dc:creator>
      <wfw:comment>http://httpcode.com/blogs/CommentView,guid,8894d5e7-e518-4ab4-93be-0a5c90caf468.aspx</wfw:comment>
      <wfw:commentRss>http://httpcode.com/blogs/SyndicationService.asmx/GetEntryCommentsRss?guid=8894d5e7-e518-4ab4-93be-0a5c90caf468</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I’ve been playing around with VS 2010 beta 2, I’ve got it installed in one of my development
VM’s which is also running the SharePoint application that I’ve been working on for
the past few months. This SharePoint application is using the 3.5 SP1 version of the
.NET framework and we haven’t yet migrated the solution and projects to VS 2010, they
are all in the 2008 format. I bring this point up, because the profiling tools in
VS 2010 don’t need a solution to be open in order to profile an application.
</p>
        <p>
 
</p>
        <p>
If your not familiar with the profiling features in VS 2010 then you should take a
read of both the <a href="http://blogs.msdn.com/profiler/">Profiler team</a><a href="http://blogs.msdn.com/profiler/archive/2009/10/22/visual-studio-2010-beta-2-available-now.aspx">blog
post</a> and also the <a href="http://www.wintellect.com/CS/blogs/jrobbins/archive/2009/10/19/vs-2010-beta-2-sampling-and-instrumentation-profiling-in-depth-first-look.aspx">post</a> from <a href="http://www.wintellect.com/CS/blogs/jrobbins/">John
Robbins</a> (debugging and profiling god).
</p>
        <p>
 
</p>
        <p>
The first step to be able to profile any .net application is:
</p>
        <p>
          <font color="#0f0f0f">
          </font> 
</p>
        <p>
          <font color="#0f0f0f">1. Open the visual studio 2010 command prompt</font>
        </p>
        <p>
2. Run the following command:  vsperfclrenv /globalsampleon
</p>
        <p>
3. Restart IIS   
</p>
        <p>
4. Now from VS you can select the Profiler –&gt; Attach/Detach option from the Analyze
menu option
</p>
        <p>
 
</p>
        <p>
          <a href="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/VS2010Beta2Profiler_B2AB/image_2.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/VS2010Beta2Profiler_B2AB/image_thumb.png" width="456" height="166" />
          </a>
        </p>
        <p>
 
</p>
        <p>
5. Now you can run through your application and the profiling information will be
captured.
</p>
        <p>
6. Once your done you’ll be taken to the main overview screen:
</p>
        <p>
 
</p>
        <p>
          <a href="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/VS2010Beta2Profiler_B2AB/ProfileOverview_2.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="ProfileOverview" border="0" alt="ProfileOverview" src="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/VS2010Beta2Profiler_B2AB/ProfileOverview_thumb.png" width="644" height="410" />
          </a>
        </p>
        <p>
 
</p>
        <p>
7. Now you can drill into the hot paths etc … The blog posts I’ve listed above can
help you drill into this in more detail.
</p>
        <p>
8. To turn off the profiling switch just run vsperfclrenv /globaloff and restart IIS
</p>
        <p>
 
</p>
        <p>
The best bit is, if you have debugging symbols all the features will work, that is
you can right click on the hot paths and the offending line of code will be shown
and highlighted. So you don’t need to convert your project to VS 2010 to get this
great profiling feature, it works with previous versions of the .NET framework.
</p>
        <img width="0" height="0" src="http://httpcode.com/blogs/aggbug.ashx?id=8894d5e7-e518-4ab4-93be-0a5c90caf468" />
      </body>
      <title>VS 2010 Beta 2 Profiler</title>
      <guid isPermaLink="false">http://httpcode.com/blogs/PermaLink,guid,8894d5e7-e518-4ab4-93be-0a5c90caf468.aspx</guid>
      <link>http://httpcode.com/blogs/PermaLink,guid,8894d5e7-e518-4ab4-93be-0a5c90caf468.aspx</link>
      <pubDate>Sat, 31 Oct 2009 15:39:00 GMT</pubDate>
      <description>&lt;p&gt;
I’ve been playing around with VS 2010 beta 2, I’ve got it installed in one of my development
VM’s which is also running the SharePoint application that I’ve been working on for
the past few months. This SharePoint application is using the 3.5 SP1 version of the
.NET framework and we haven’t yet migrated the solution and projects to VS 2010, they
are all in the 2008 format. I bring this point up, because the profiling tools in
VS 2010 don’t need a solution to be open in order to profile an application.
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
If your not familiar with the profiling features in VS 2010 then you should take a
read of both the &lt;a href="http://blogs.msdn.com/profiler/"&gt;Profiler team&lt;/a&gt; &lt;a href="http://blogs.msdn.com/profiler/archive/2009/10/22/visual-studio-2010-beta-2-available-now.aspx"&gt;blog
post&lt;/a&gt; and also the &lt;a href="http://www.wintellect.com/CS/blogs/jrobbins/archive/2009/10/19/vs-2010-beta-2-sampling-and-instrumentation-profiling-in-depth-first-look.aspx"&gt;post&lt;/a&gt; from &lt;a href="http://www.wintellect.com/CS/blogs/jrobbins/"&gt;John
Robbins&lt;/a&gt; (debugging and profiling god).
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
The first step to be able to profile any .net application is:
&lt;/p&gt;
&lt;p&gt;
&lt;font color="#0f0f0f"&gt;&lt;/font&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;font color="#0f0f0f"&gt;1. Open the visual studio 2010 command prompt&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
2. Run the following command:&amp;nbsp; vsperfclrenv /globalsampleon
&lt;/p&gt;
&lt;p&gt;
3. Restart IIS&amp;nbsp;&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
4. Now from VS you can select the Profiler –&amp;gt; Attach/Detach option from the Analyze
menu option
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/VS2010Beta2Profiler_B2AB/image_2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/VS2010Beta2Profiler_B2AB/image_thumb.png" width="456" height="166"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
5. Now you can run through your application and the profiling information will be
captured.
&lt;/p&gt;
&lt;p&gt;
6. Once your done you’ll be taken to the main overview screen:
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/VS2010Beta2Profiler_B2AB/ProfileOverview_2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="ProfileOverview" border="0" alt="ProfileOverview" src="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/VS2010Beta2Profiler_B2AB/ProfileOverview_thumb.png" width="644" height="410"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
7. Now you can drill into the hot paths etc … The blog posts I’ve listed above can
help you drill into this in more detail.
&lt;/p&gt;
&lt;p&gt;
8. To turn off the profiling switch just run vsperfclrenv /globaloff and restart IIS
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
The best bit is, if you have debugging symbols all the features will work, that is
you can right click on the hot paths and the offending line of code will be shown
and highlighted. So you don’t need to convert your project to VS 2010 to get this
great profiling feature, it works with previous versions of the .NET framework.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://httpcode.com/blogs/aggbug.ashx?id=8894d5e7-e518-4ab4-93be-0a5c90caf468" /&gt;</description>
      <comments>http://httpcode.com/blogs/CommentView,guid,8894d5e7-e518-4ab4-93be-0a5c90caf468.aspx</comments>
      <category>VS 2010</category>
    </item>
    <item>
      <trackback:ping>http://httpcode.com/blogs/Trackback.aspx?guid=345e7d87-cc9c-4801-99df-c22c3a6459ff</trackback:ping>
      <pingback:server>http://httpcode.com/blogs/pingback.aspx</pingback:server>
      <pingback:target>http://httpcode.com/blogs/PermaLink,guid,345e7d87-cc9c-4801-99df-c22c3a6459ff.aspx</pingback:target>
      <dc:creator>Daniel Pollard</dc:creator>
      <wfw:comment>http://httpcode.com/blogs/CommentView,guid,345e7d87-cc9c-4801-99df-c22c3a6459ff.aspx</wfw:comment>
      <wfw:commentRss>http://httpcode.com/blogs/SyndicationService.asmx/GetEntryCommentsRss?guid=345e7d87-cc9c-4801-99df-c22c3a6459ff</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Nice message after installing Visual Studio 2010 Beta 2:
</p>
        <p>
 
</p>
        <p>
          <a href="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/FunnyVS2010Beta2InstallationMessage_A2D0/BetaErrorMsg_2.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="BetaErrorMsg" border="0" alt="BetaErrorMsg" src="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/FunnyVS2010Beta2InstallationMessage_A2D0/BetaErrorMsg_thumb.png" width="334" height="202" />
          </a>
        </p>
        <p>
 
</p>
        <p>
Everything is OK? … must be an error :)
</p>
        <img width="0" height="0" src="http://httpcode.com/blogs/aggbug.ashx?id=345e7d87-cc9c-4801-99df-c22c3a6459ff" />
      </body>
      <title>Funny VS 2010 Beta 2 Installation Message</title>
      <guid isPermaLink="false">http://httpcode.com/blogs/PermaLink,guid,345e7d87-cc9c-4801-99df-c22c3a6459ff.aspx</guid>
      <link>http://httpcode.com/blogs/PermaLink,guid,345e7d87-cc9c-4801-99df-c22c3a6459ff.aspx</link>
      <pubDate>Mon, 19 Oct 2009 14:34:00 GMT</pubDate>
      <description>&lt;p&gt;
Nice message after installing Visual Studio 2010 Beta 2:
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/FunnyVS2010Beta2InstallationMessage_A2D0/BetaErrorMsg_2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="BetaErrorMsg" border="0" alt="BetaErrorMsg" src="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/FunnyVS2010Beta2InstallationMessage_A2D0/BetaErrorMsg_thumb.png" width="334" height="202"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Everything is OK? … must be an error :)
&lt;/p&gt;
&lt;img width="0" height="0" src="http://httpcode.com/blogs/aggbug.ashx?id=345e7d87-cc9c-4801-99df-c22c3a6459ff" /&gt;</description>
      <comments>http://httpcode.com/blogs/CommentView,guid,345e7d87-cc9c-4801-99df-c22c3a6459ff.aspx</comments>
      <category>VS 2010</category>
    </item>
    <item>
      <trackback:ping>http://httpcode.com/blogs/Trackback.aspx?guid=393eba9e-7204-4fe5-ba87-af39fa689cf8</trackback:ping>
      <pingback:server>http://httpcode.com/blogs/pingback.aspx</pingback:server>
      <pingback:target>http://httpcode.com/blogs/PermaLink,guid,393eba9e-7204-4fe5-ba87-af39fa689cf8.aspx</pingback:target>
      <dc:creator>Daniel Pollard</dc:creator>
      <wfw:comment>http://httpcode.com/blogs/CommentView,guid,393eba9e-7204-4fe5-ba87-af39fa689cf8.aspx</wfw:comment>
      <wfw:commentRss>http://httpcode.com/blogs/SyndicationService.asmx/GetEntryCommentsRss?guid=393eba9e-7204-4fe5-ba87-af39fa689cf8</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I came across a rather interesting problem the other day (interesting enough to blog
anyway).
</p>
        <p>
We have a development server that we are building some SharePoint web parts on, all
of the developers have local admin rights to the box. We asked a normal user to have
a look at some functionality that should be available to them, but when they browsed
to the site they got a 403 forbidden error message. However when the developer requested
that very same page it rendered fine. The weird thing was that if the original user
(not the dev) then requested the page once again, it all rendered fine.
</p>
        <p>
We had a look in the SharePoint Logs and found that the assembly in the bin folder
was denying access to the non developer, but once a dev hit the box the assembly was
loaded fine and stayed in memory until the app pool was recycled.
</p>
        <p>
So the solution was to grant all users access to the bin directory. This wouldn’t
be an issue in production because we will eventually GAC deploy these assemblies.
</p>
        <p>
But I did think it was a fun little exercise to track down the root cause.
</p>
        <img width="0" height="0" src="http://httpcode.com/blogs/aggbug.ashx?id=393eba9e-7204-4fe5-ba87-af39fa689cf8" />
      </body>
      <title>403 Forbidden for some users</title>
      <guid isPermaLink="false">http://httpcode.com/blogs/PermaLink,guid,393eba9e-7204-4fe5-ba87-af39fa689cf8.aspx</guid>
      <link>http://httpcode.com/blogs/PermaLink,guid,393eba9e-7204-4fe5-ba87-af39fa689cf8.aspx</link>
      <pubDate>Fri, 16 Oct 2009 18:30:00 GMT</pubDate>
      <description>&lt;p&gt;
I came across a rather interesting problem the other day (interesting enough to blog
anyway).
&lt;/p&gt;
&lt;p&gt;
We have a development server that we are building some SharePoint web parts on, all
of the developers have local admin rights to the box. We asked a normal user to have
a look at some functionality that should be available to them, but when they browsed
to the site they got a 403 forbidden error message. However when the developer requested
that very same page it rendered fine. The weird thing was that if the original user
(not the dev) then requested the page once again, it all rendered fine.
&lt;/p&gt;
&lt;p&gt;
We had a look in the SharePoint Logs and found that the assembly in the bin folder
was denying access to the non developer, but once a dev hit the box the assembly was
loaded fine and stayed in memory until the app pool was recycled.
&lt;/p&gt;
&lt;p&gt;
So the solution was to grant all users access to the bin directory. This wouldn’t
be an issue in production because we will eventually GAC deploy these assemblies.
&lt;/p&gt;
&lt;p&gt;
But I did think it was a fun little exercise to track down the root cause.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://httpcode.com/blogs/aggbug.ashx?id=393eba9e-7204-4fe5-ba87-af39fa689cf8" /&gt;</description>
      <comments>http://httpcode.com/blogs/CommentView,guid,393eba9e-7204-4fe5-ba87-af39fa689cf8.aspx</comments>
      <category>Tip</category>
      <category>Work</category>
    </item>
    <item>
      <trackback:ping>http://httpcode.com/blogs/Trackback.aspx?guid=f47960f8-7dc2-4758-8c96-387c36321cd2</trackback:ping>
      <pingback:server>http://httpcode.com/blogs/pingback.aspx</pingback:server>
      <pingback:target>http://httpcode.com/blogs/PermaLink,guid,f47960f8-7dc2-4758-8c96-387c36321cd2.aspx</pingback:target>
      <dc:creator>Daniel Pollard</dc:creator>
      <wfw:comment>http://httpcode.com/blogs/CommentView,guid,f47960f8-7dc2-4758-8c96-387c36321cd2.aspx</wfw:comment>
      <wfw:commentRss>http://httpcode.com/blogs/SyndicationService.asmx/GetEntryCommentsRss?guid=f47960f8-7dc2-4758-8c96-387c36321cd2</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Windows 7 contains a really nice tool called the Problem Steps Recorder:
</p>
        <p>
 
</p>
        <p>
It can be found via the Windows 7 start menu by typing ‘problem step’
</p>
        <p>
          <a href="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/ProblemStepRecorderAutomatedDocumentatio_AEEF/image_2.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/ProblemStepRecorderAutomatedDocumentatio_AEEF/image_thumb.png" width="396" height="142" />
          </a>
        </p>
        <p>
 
</p>
        <p>
Once it’s running you get the following UI:
</p>
        <p>
 
</p>
        <p>
 <a href="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/ProblemStepRecorderAutomatedDocumentatio_AEEF/image_4.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/ProblemStepRecorderAutomatedDocumentatio_AEEF/image_thumb_1.png" width="446" height="73" /></a></p>
        <p>
 
</p>
        <p>
From here you can record all the clicks and keystrokes that your undertaking, you
can even add comments to parts of your display. It finally saves the file as a zip
file, which contains a .mht file that can be viewed in your browser. This output file
will list things like version numbers of applications running as well as a range of
screenshots of each major activity recorded.
</p>
        <p>
 
</p>
        <p>
Now this is all well and good for sorting your mum’s computer problems, but as an
IT pro who has had to document some awfully boring processes, I really think this
tool will help me the next time I need to document the install of some software, or
some mundane configuration change.
</p>
        <img width="0" height="0" src="http://httpcode.com/blogs/aggbug.ashx?id=f47960f8-7dc2-4758-8c96-387c36321cd2" />
      </body>
      <title>Problem Step Recorder – Automated Documentation Tool?</title>
      <guid isPermaLink="false">http://httpcode.com/blogs/PermaLink,guid,f47960f8-7dc2-4758-8c96-387c36321cd2.aspx</guid>
      <link>http://httpcode.com/blogs/PermaLink,guid,f47960f8-7dc2-4758-8c96-387c36321cd2.aspx</link>
      <pubDate>Mon, 21 Sep 2009 16:25:00 GMT</pubDate>
      <description>&lt;p&gt;
Windows 7 contains a really nice tool called the Problem Steps Recorder:
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
It can be found via the Windows 7 start menu by typing ‘problem step’
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/ProblemStepRecorderAutomatedDocumentatio_AEEF/image_2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/ProblemStepRecorderAutomatedDocumentatio_AEEF/image_thumb.png" width="396" height="142"&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Once it’s running you get the following UI:
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;&lt;a href="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/ProblemStepRecorderAutomatedDocumentatio_AEEF/image_4.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://httpcode.com/blogs/content/binary/WindowsLiveWriter/ProblemStepRecorderAutomatedDocumentatio_AEEF/image_thumb_1.png" width="446" height="73"&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
From here you can record all the clicks and keystrokes that your undertaking, you
can even add comments to parts of your display. It finally saves the file as a zip
file, which contains a .mht file that can be viewed in your browser. This output file
will list things like version numbers of applications running as well as a range of
screenshots of each major activity recorded.
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Now this is all well and good for sorting your mum’s computer problems, but as an
IT pro who has had to document some awfully boring processes, I really think this
tool will help me the next time I need to document the install of some software, or
some mundane configuration change.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://httpcode.com/blogs/aggbug.ashx?id=f47960f8-7dc2-4758-8c96-387c36321cd2" /&gt;</description>
      <comments>http://httpcode.com/blogs/CommentView,guid,f47960f8-7dc2-4758-8c96-387c36321cd2.aspx</comments>
      <category>Tip</category>
      <category>Windows 7</category>
    </item>
    <item>
      <trackback:ping>http://httpcode.com/blogs/Trackback.aspx?guid=30d9079a-2904-4667-8c93-567722861a14</trackback:ping>
      <pingback:server>http://httpcode.com/blogs/pingback.aspx</pingback:server>
      <pingback:target>http://httpcode.com/blogs/PermaLink,guid,30d9079a-2904-4667-8c93-567722861a14.aspx</pingback:target>
      <dc:creator>Daniel Pollard</dc:creator>
      <wfw:comment>http://httpcode.com/blogs/CommentView,guid,30d9079a-2904-4667-8c93-567722861a14.aspx</wfw:comment>
      <wfw:commentRss>http://httpcode.com/blogs/SyndicationService.asmx/GetEntryCommentsRss?guid=30d9079a-2904-4667-8c93-567722861a14</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I’ve been working on a project that involves implementing a blogging system inside
SharePoint, the out of the box SharePoint blogging system was unsuitable and the <a href="http://cks.codeplex.com/Wiki/View.aspx?title=Enhanced%20Blog%20Edition">Community
Kit for SharePoint</a> didn’t solve our issues. 
</p>
        <p>
So the system we developed was lightly based on the open source <a href="http://www.dotnetblogengine.net/">.NET
Blog Engine</a> which includes comprehensive support for the <a href="http://www.xmlrpc.com/metaWeblogApi">MetaWebBlog
API</a>. This API allows a interaction with a blogging system so that blog posts can
be added, deleted and updated, but it also provides provisions for managing things
like categories and comments.
</p>
        <p>
The main motivation for supporting the MetaWebBlog API is <a href="http://windowslivewriter.spaces.live.com/default.aspx">Windows
Live Writer</a> (WLW) this great tool really makes publishing to a blog a simple task.
So I happily added the MetaWebBlog API and quickly found that windows live writer
doesn’t support windows authentication. WLW supports a nice feature called <a href="http://en.wikipedia.org/wiki/Really_Simple_Discovery">Really
Simple Discovery</a> (RSD) where it can just be pointed to a blog’s home page and
it can get all the configuration needs. By not supporting windows authentication we
lost the auto discovery features.
</p>
        <p>
 
</p>
        <p>
So I could still enable anonymous access to the MetaWebBlog.axd and wlwriter.xml (a
file that tells WLW what capabilities your blog has), so now with some manual steps
in WLW I could select the MetaWebBlog API and give it the url to use. My next problem
was that my blogging system was all based around windows authentication. Every user
has a blog that is based around their network credentials, I needed my metawebblog
API implementation to validate the user to the windows network:
</p>
        <p>
 
</p>
        <p>
With the following P/Invoke definitions:
</p>
        <p>
 
</p>
        <pre class="csharpcode">[DllImport(<span class="str">"advapi32.dll"</span>, SetLastError
= <span class="kwrd">true</span>)] <span class="kwrd">public</span><span class="kwrd">static</span><span class="kwrd">extern</span><span class="kwrd">bool</span> LogonUser(String
lpszUsername, String lpszDomain, String lpszPassword, <span class="kwrd">int</span> dwLogonType, <span class="kwrd">int</span> dwLogonProvider, <span class="kwrd">ref</span> IntPtr
phToken); [DllImport(<span class="str">"kernel32.dll"</span>, CharSet = CharSet.Auto)] <span class="kwrd">public</span><span class="kwrd">extern</span><span class="kwrd">static</span><span class="kwrd">bool</span> CloseHandle(IntPtr
handle); [DllImport(<span class="str">"advapi32.dll"</span>, CharSet = CharSet.Auto,
SetLastError = <span class="kwrd">true</span>)] <span class="kwrd">public</span><span class="kwrd">extern</span><span class="kwrd">static</span><span class="kwrd">bool</span> DuplicateToken(IntPtr
ExistingTokenHandle, <span class="kwrd">int</span> SECURITY_IMPERSONATION_LEVEL, <span class="kwrd">ref</span> IntPtr
DuplicateTokenHandle); </pre>
        <pre class="csharpcode"> </pre>
        <style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
        <p>
Now in all of my metawebblog API calls I could use a method like:
</p>
        <p>
 
</p>
        <p>
 
</p>
        <pre class="csharpcode">
          <span class="kwrd">string</span> username
= <span class="kwrd">string</span>.Empty; <span class="kwrd">string</span> password
= input.Password; <span class="kwrd">string</span> domain = <span class="kwrd">string</span>.Empty; <span class="kwrd">if</span> (input.UserName.Contains(<span class="str"><a>\\</a></span>))
{ <span class="kwrd">string</span>[] usernameParts = input.UserName.Split(<span class="str">'\\'</span>); <span class="kwrd">if</span> (usernameParts.Length
&gt; 1) { domain = usernameParts[0]; username = usernameParts[1]; } } <span class="kwrd">else</span> {
username = input.UserName; } IntPtr tokenHandle = IntPtr.Zero; <span class="kwrd">bool</span> returnValue
= LogonUser(username, domain, password,3, 0, <span class="kwrd">ref</span> tokenHandle); <span class="kwrd">if</span> (returnValue
== <span class="kwrd">false</span>) { <span class="rem">//error not a valid user ..
return</span><span class="kwrd">throw</span><span class="kwrd">new</span> MetaWeblogException(<span class="str">"11"</span>, <span class="str">"User
authentication failed"</span>); } <span class="kwrd">if</span> (tokenHandle != IntPtr.Zero)
CloseHandle(tokenHandle);</pre>
        <style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
        <p>
This code will return an invalid authentication message to WLW if the user doesn’t
provide the correct domain, username and password (you could easily remove the need
for a domain, I needed to keep it).
</p>
        <p>
I’d like to say that its all good but really end users won’t go to the effort of following
steps to configure WLW, the RSD is a killer feature in making web blogs accessible
to end users. Fingers crossed that WLW will support windows authentication in a future
version.
</p>
        <img width="0" height="0" src="http://httpcode.com/blogs/aggbug.ashx?id=30d9079a-2904-4667-8c93-567722861a14" />
      </body>
      <title>MetaWebBlog API, Windows Live Writer and Windows Authentication</title>
      <guid isPermaLink="false">http://httpcode.com/blogs/PermaLink,guid,30d9079a-2904-4667-8c93-567722861a14.aspx</guid>
      <link>http://httpcode.com/blogs/PermaLink,guid,30d9079a-2904-4667-8c93-567722861a14.aspx</link>
      <pubDate>Mon, 21 Sep 2009 15:32:00 GMT</pubDate>
      <description>&lt;p&gt;
I’ve been working on a project that involves implementing a blogging system inside
SharePoint, the out of the box SharePoint blogging system was unsuitable and the &lt;a href="http://cks.codeplex.com/Wiki/View.aspx?title=Enhanced%20Blog%20Edition"&gt;Community
Kit for SharePoint&lt;/a&gt; didn’t solve our issues. 
&lt;/p&gt;
&lt;p&gt;
So the system we developed was lightly based on the open source &lt;a href="http://www.dotnetblogengine.net/"&gt;.NET
Blog Engine&lt;/a&gt; which includes comprehensive support for the &lt;a href="http://www.xmlrpc.com/metaWeblogApi"&gt;MetaWebBlog
API&lt;/a&gt;. This API allows a interaction with a blogging system so that blog posts can
be added, deleted and updated, but it also provides provisions for managing things
like categories and comments.
&lt;/p&gt;
&lt;p&gt;
The main motivation for supporting the MetaWebBlog API is &lt;a href="http://windowslivewriter.spaces.live.com/default.aspx"&gt;Windows
Live Writer&lt;/a&gt; (WLW) this great tool really makes publishing to a blog a simple task.
So I happily added the MetaWebBlog API and quickly found that windows live writer
doesn’t support windows authentication. WLW supports a nice feature called &lt;a href="http://en.wikipedia.org/wiki/Really_Simple_Discovery"&gt;Really
Simple Discovery&lt;/a&gt; (RSD) where it can just be pointed to a blog’s home page and
it can get all the configuration needs. By not supporting windows authentication we
lost the auto discovery features.
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
So I could still enable anonymous access to the MetaWebBlog.axd and wlwriter.xml (a
file that tells WLW what capabilities your blog has), so now with some manual steps
in WLW I could select the MetaWebBlog API and give it the url to use. My next problem
was that my blogging system was all based around windows authentication. Every user
has a blog that is based around their network credentials, I needed my metawebblog
API implementation to validate the user to the windows network:
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
With the following P/Invoke definitions:
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;[DllImport(&lt;span class="str"&gt;"advapi32.dll"&lt;/span&gt;, SetLastError
= &lt;span class="kwrd"&gt;true&lt;/span&gt;)] &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;extern&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; LogonUser(String
lpszUsername, String lpszDomain, String lpszPassword, &lt;span class="kwrd"&gt;int&lt;/span&gt; dwLogonType, &lt;span class="kwrd"&gt;int&lt;/span&gt; dwLogonProvider, &lt;span class="kwrd"&gt;ref&lt;/span&gt; IntPtr
phToken); [DllImport(&lt;span class="str"&gt;"kernel32.dll"&lt;/span&gt;, CharSet = CharSet.Auto)] &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;extern&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; CloseHandle(IntPtr
handle); [DllImport(&lt;span class="str"&gt;"advapi32.dll"&lt;/span&gt;, CharSet = CharSet.Auto,
SetLastError = &lt;span class="kwrd"&gt;true&lt;/span&gt;)] &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;extern&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; DuplicateToken(IntPtr
ExistingTokenHandle, &lt;span class="kwrd"&gt;int&lt;/span&gt; SECURITY_IMPERSONATION_LEVEL, &lt;span class="kwrd"&gt;ref&lt;/span&gt; IntPtr
DuplicateTokenHandle); &lt;/pre&gt;&lt;pre class="csharpcode"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;p&gt;
Now in all of my metawebblog API calls I could use a method like:
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;                &lt;span class="kwrd"&gt;string&lt;/span&gt; username
= &lt;span class="kwrd"&gt;string&lt;/span&gt;.Empty; &lt;span class="kwrd"&gt;string&lt;/span&gt; password
= input.Password; &lt;span class="kwrd"&gt;string&lt;/span&gt; domain = &lt;span class="kwrd"&gt;string&lt;/span&gt;.Empty; &lt;span class="kwrd"&gt;if&lt;/span&gt; (input.UserName.Contains(&lt;span class="str"&gt;&lt;a&gt;\\&lt;/a&gt;&lt;/span&gt;))
{ &lt;span class="kwrd"&gt;string&lt;/span&gt;[] usernameParts = input.UserName.Split(&lt;span class="str"&gt;'\\'&lt;/span&gt;); &lt;span class="kwrd"&gt;if&lt;/span&gt; (usernameParts.Length
&amp;gt; 1) { domain = usernameParts[0]; username = usernameParts[1]; } } &lt;span class="kwrd"&gt;else&lt;/span&gt; {
username = input.UserName; } IntPtr tokenHandle = IntPtr.Zero; &lt;span class="kwrd"&gt;bool&lt;/span&gt; returnValue
= LogonUser(username, domain, password,3, 0, &lt;span class="kwrd"&gt;ref&lt;/span&gt; tokenHandle); &lt;span class="kwrd"&gt;if&lt;/span&gt; (returnValue
== &lt;span class="kwrd"&gt;false&lt;/span&gt;) { &lt;span class="rem"&gt;//error not a valid user ..
return&lt;/span&gt; &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; MetaWeblogException(&lt;span class="str"&gt;"11"&lt;/span&gt;, &lt;span class="str"&gt;"User
authentication failed"&lt;/span&gt;); } &lt;span class="kwrd"&gt;if&lt;/span&gt; (tokenHandle != IntPtr.Zero)
CloseHandle(tokenHandle);&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;p&gt;
This code will return an invalid authentication message to WLW if the user doesn’t
provide the correct domain, username and password (you could easily remove the need
for a domain, I needed to keep it).
&lt;/p&gt;
&lt;p&gt;
I’d like to say that its all good but really end users won’t go to the effort of following
steps to configure WLW, the RSD is a killer feature in making web blogs accessible
to end users. Fingers crossed that WLW will support windows authentication in a future
version.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://httpcode.com/blogs/aggbug.ashx?id=30d9079a-2904-4667-8c93-567722861a14" /&gt;</description>
      <comments>http://httpcode.com/blogs/CommentView,guid,30d9079a-2904-4667-8c93-567722861a14.aspx</comments>
      <category>code</category>
      <category>Tip</category>
    </item>
    <item>
      <trackback:ping>http://httpcode.com/blogs/Trackback.aspx?guid=7d5bb8f8-ec8f-4f0e-9a12-da32f07d87f1</trackback:ping>
      <pingback:server>http://httpcode.com/blogs/pingback.aspx</pingback:server>
      <pingback:target>http://httpcode.com/blogs/PermaLink,guid,7d5bb8f8-ec8f-4f0e-9a12-da32f07d87f1.aspx</pingback:target>
      <dc:creator>Daniel Pollard</dc:creator>
      <wfw:comment>http://httpcode.com/blogs/CommentView,guid,7d5bb8f8-ec8f-4f0e-9a12-da32f07d87f1.aspx</wfw:comment>
      <wfw:commentRss>http://httpcode.com/blogs/SyndicationService.asmx/GetEntryCommentsRss?guid=7d5bb8f8-ec8f-4f0e-9a12-da32f07d87f1</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
We’ve all probably worked on projects in the last 5 years or so that have involved
reworking applications that were once built in MS access, in my case it was an access
system that stored important safety testing information that was captured in an engineering
workshop. It was originally designed and built by a mechanical engineer, who didn’t
know much about database design.
</p>
        <p>
The system was redeveloped for a number of reasons including:
</p>
        <ul>
          <li>
The data couldn’t be shared, it was locked away on a PC in the workshop, no analysis
of the data could be performed.</li>
          <li>
It didn’t scale well, only one user at a time could access it.</li>
        </ul>
        <p>
There are lots of other reasons why MS access shouldn’t be used for this type of information,
but my point was that Access is a pretty poor tool for critical business information
because it was difficult for the business to <strong>access</strong> this information.
I think most people would share this view.
</p>
        <p>
Lets compare a couple of scenarios with SharePoint as the tool, so all the information
would be stored in a list:
</p>
        <ul>
          <li>
The data can be shared by webservices and RSS, with effort.</li>
          <li>
It can scale, multiple users can access it at the same time.</li>
        </ul>
        <p>
But is the business data in a SharePoint list really easier to work with? 
</p>
        <p>
Can it:
</p>
        <ul>
          <li>
Be used in SQL Server analysis cube?</li>
          <li>
Easily used in Reporting Services?</li>
          <li>
Joined with other business data to see correlations?</li>
          <li>
Perform complex real world queries?</li>
          <li>
Do you really want to model your business data based on the limitations of SharePoint?</li>
        </ul>
        <p>
The answer is no.
</p>
        <p>
 
</p>
        <p>
I still think that business data needs to live in a system designed for business data,
i.e. A database: SQL Server. 
</p>
        <p>
From here it can be queried, joined and more importantly <strong>shared</strong>,
whether that be back into SharePoint or any other tool that supports a database (Reporting
Services, Performance Point, Analysis Services etc).
</p>
        <p>
 
</p>
        <p>
So now that brings me back to my comparison with MS Access, we are now doing lots
of work moving systems away from MS Access, will we be doing the same thing in 5 years
time, moving our SharePoint lists away from SharePoint?
</p>
        <p>
 
</p>
        <p>
I think SharePoint lists have their place, no question, but not for line of business
data. Keep the SP lists for trivial data that is not important to the overall operation
of your business.
</p>
        <img width="0" height="0" src="http://httpcode.com/blogs/aggbug.ashx?id=7d5bb8f8-ec8f-4f0e-9a12-da32f07d87f1" />
      </body>
      <title>Is SharePoint the next MS Access?</title>
      <guid isPermaLink="false">http://httpcode.com/blogs/PermaLink,guid,7d5bb8f8-ec8f-4f0e-9a12-da32f07d87f1.aspx</guid>
      <link>http://httpcode.com/blogs/PermaLink,guid,7d5bb8f8-ec8f-4f0e-9a12-da32f07d87f1.aspx</link>
      <pubDate>Mon, 21 Sep 2009 14:43:00 GMT</pubDate>
      <description>&lt;p&gt;
We’ve all probably worked on projects in the last 5 years or so that have involved
reworking applications that were once built in MS access, in my case it was an access
system that stored important safety testing information that was captured in an engineering
workshop. It was originally designed and built by a mechanical engineer, who didn’t
know much about database design.
&lt;/p&gt;
&lt;p&gt;
The system was redeveloped for a number of reasons including:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
The data couldn’t be shared, it was locked away on a PC in the workshop, no analysis
of the data could be performed.&lt;/li&gt;
&lt;li&gt;
It didn’t scale well, only one user at a time could access it.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
There are lots of other reasons why MS access shouldn’t be used for this type of information,
but my point was that Access is a pretty poor tool for critical business information
because it was difficult for the business to &lt;strong&gt;access&lt;/strong&gt; this information.
I think most people would share this view.
&lt;/p&gt;
&lt;p&gt;
Lets compare a couple of scenarios with SharePoint as the tool, so all the information
would be stored in a list:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
The data can be shared by webservices and RSS, with effort.&lt;/li&gt;
&lt;li&gt;
It can scale, multiple users can access it at the same time.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
But is the business data in a SharePoint list really easier to work with? 
&lt;/p&gt;
&lt;p&gt;
Can it:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Be used in SQL Server analysis cube?&lt;/li&gt;
&lt;li&gt;
Easily used in Reporting Services?&lt;/li&gt;
&lt;li&gt;
Joined with other business data to see correlations?&lt;/li&gt;
&lt;li&gt;
Perform complex real world queries?&lt;/li&gt;
&lt;li&gt;
Do you really want to model your business data based on the limitations of SharePoint?&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
The answer is no.
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
I still think that business data needs to live in a system designed for business data,
i.e. A database: SQL Server. 
&lt;/p&gt;
&lt;p&gt;
From here it can be queried, joined and more importantly &lt;strong&gt;shared&lt;/strong&gt;,
whether that be back into SharePoint or any other tool that supports a database (Reporting
Services, Performance Point, Analysis Services etc).
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
So now that brings me back to my comparison with MS Access, we are now doing lots
of work moving systems away from MS Access, will we be doing the same thing in 5 years
time, moving our SharePoint lists away from SharePoint?
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
I think SharePoint lists have their place, no question, but not for line of business
data. Keep the SP lists for trivial data that is not important to the overall operation
of your business.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://httpcode.com/blogs/aggbug.ashx?id=7d5bb8f8-ec8f-4f0e-9a12-da32f07d87f1" /&gt;</description>
      <comments>http://httpcode.com/blogs/CommentView,guid,7d5bb8f8-ec8f-4f0e-9a12-da32f07d87f1.aspx</comments>
      <category>Sharepoint</category>
    </item>
    <item>
      <trackback:ping>http://httpcode.com/blogs/Trackback.aspx?guid=039f9eda-4b47-45cb-8d04-3ca3bae6e96e</trackback:ping>
      <pingback:server>http://httpcode.com/blogs/pingback.aspx</pingback:server>
      <pingback:target>http://httpcode.com/blogs/PermaLink,guid,039f9eda-4b47-45cb-8d04-3ca3bae6e96e.aspx</pingback:target>
      <dc:creator>Daniel Pollard</dc:creator>
      <wfw:comment>http://httpcode.com/blogs/CommentView,guid,039f9eda-4b47-45cb-8d04-3ca3bae6e96e.aspx</wfw:comment>
      <wfw:commentRss>http://httpcode.com/blogs/SyndicationService.asmx/GetEntryCommentsRss?guid=039f9eda-4b47-45cb-8d04-3ca3bae6e96e</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
With the upcoming <a href="http://www.mssharepointconference.com/">SharePoint conference</a> releasing
information about SharePoint 2010, it won’t be too long before everyone will be looking
at the product. Interestingly SharePoint 2010 is 64 bit only, this will have an impact
on developers using Virtual PC 2007, which only supports 32 bit guest OS’s.
</p>
        <p>
However windows 7 and Server 2008 R2 supports <a href="http://www.hanselman.com/blog/LessVirtualMoreMachineWindows7AndTheMagicOfBootToVHD.aspx">boot
to VHD</a>, this provides the ability to create a single VHD file that can booted.
Once you’ve booted up the VHD your computer has access to all of it’s CPU cores, which
is a major win. I’ve read that the performance hit of virtualising the file system
to write to the VHD is around 5%, so it’s barely noticeable. Most importantly you
can boot into a 64 bit OS where SharePoint 2010 can be installed.
</p>
        <p>
To recap, the advantages of boot to VHD:
</p>
        <ul>
          <li>
Can run 64 bit machines</li>
          <li>
Access to all CPU cores</li>
          <li>
Still keep portability by way of VHD files</li>
        </ul>
        <p>
Disadvantages
</p>
        <ul>
          <li>
Can’t multitask with the primary OS, the VHD OS is the primary OS</li>
          <li>
Need to upgrade to windows 7 or server 2008 R2 (Not really a disadvantage, but might
be an issue in corporate environments)</li>
        </ul>
        <img width="0" height="0" src="http://httpcode.com/blogs/aggbug.ashx?id=039f9eda-4b47-45cb-8d04-3ca3bae6e96e" />
      </body>
      <title>Boot to VHD – Future SharePoint Development</title>
      <guid isPermaLink="false">http://httpcode.com/blogs/PermaLink,guid,039f9eda-4b47-45cb-8d04-3ca3bae6e96e.aspx</guid>
      <link>http://httpcode.com/blogs/PermaLink,guid,039f9eda-4b47-45cb-8d04-3ca3bae6e96e.aspx</link>
      <pubDate>Mon, 21 Sep 2009 12:49:00 GMT</pubDate>
      <description>&lt;p&gt;
With the upcoming &lt;a href="http://www.mssharepointconference.com/"&gt;SharePoint conference&lt;/a&gt; releasing
information about SharePoint 2010, it won’t be too long before everyone will be looking
at the product. Interestingly SharePoint 2010 is 64 bit only, this will have an impact
on developers using Virtual PC 2007, which only supports 32 bit guest OS’s.
&lt;/p&gt;
&lt;p&gt;
However windows 7 and Server 2008 R2 supports &lt;a href="http://www.hanselman.com/blog/LessVirtualMoreMachineWindows7AndTheMagicOfBootToVHD.aspx"&gt;boot
to VHD&lt;/a&gt;, this provides the ability to create a single VHD file that can booted.
Once you’ve booted up the VHD your computer has access to all of it’s CPU cores, which
is a major win. I’ve read that the performance hit of virtualising the file system
to write to the VHD is around 5%, so it’s barely noticeable. Most importantly you
can boot into a 64 bit OS where SharePoint 2010 can be installed.
&lt;/p&gt;
&lt;p&gt;
To recap, the advantages of boot to VHD:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Can run 64 bit machines&lt;/li&gt;
&lt;li&gt;
Access to all CPU cores&lt;/li&gt;
&lt;li&gt;
Still keep portability by way of VHD files&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
Disadvantages
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Can’t multitask with the primary OS, the VHD OS is the primary OS&lt;/li&gt;
&lt;li&gt;
Need to upgrade to windows 7 or server 2008 R2 (Not really a disadvantage, but might
be an issue in corporate environments)&lt;/li&gt;
&lt;/ul&gt;
&lt;img width="0" height="0" src="http://httpcode.com/blogs/aggbug.ashx?id=039f9eda-4b47-45cb-8d04-3ca3bae6e96e" /&gt;</description>
      <comments>http://httpcode.com/blogs/CommentView,guid,039f9eda-4b47-45cb-8d04-3ca3bae6e96e.aspx</comments>
      <category>SP 2010</category>
      <category>Windows 7</category>
    </item>
    <item>
      <trackback:ping>http://httpcode.com/blogs/Trackback.aspx?guid=961b0893-cebf-47e2-a608-9562136bcad4</trackback:ping>
      <pingback:server>http://httpcode.com/blogs/pingback.aspx</pingback:server>
      <pingback:target>http://httpcode.com/blogs/PermaLink,guid,961b0893-cebf-47e2-a608-9562136bcad4.aspx</pingback:target>
      <dc:creator>Daniel Pollard</dc:creator>
      <wfw:comment>http://httpcode.com/blogs/CommentView,guid,961b0893-cebf-47e2-a608-9562136bcad4.aspx</wfw:comment>
      <wfw:commentRss>http://httpcode.com/blogs/SyndicationService.asmx/GetEntryCommentsRss?guid=961b0893-cebf-47e2-a608-9562136bcad4</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
By default SharePoint will use impersonation, so the web.config file will have the
setting:
</p>
        <div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
          <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
              <span style="color: #0000ff">&lt;</span>
              <span style="color: #800000">identity</span>
              <span style="color: #ff0000">impersonate</span>
              <span style="color: #0000ff">="true"</span>
              <span style="color: #0000ff">/&gt;</span>
            </pre>
            <!--CRLF-->
          </div>
        </div>
        <p>
        </p>
        <p>
          <font color="#0f0f0f">
          </font> 
</p>
        <p>
This means that if you try and connect to a SQL server database from say a custom
web part, the connection will appear to SQL server as the user that requested the
page. This is very useful if you care about the actual user, so for example if the
database has permissions set based on this assumption. 
</p>
        <p>
However it is often useful to have just the application pool account connect to the
SQL Server database or you may wish to give the application pool account permissions
to connect to active directory but not every user. 
</p>
        <p>
It this case you will need to impersonate the application pool account. There is a
bit of code floating around the web that uses P/Invoke to call ReverToSelf() from
the advapi32.dll. It turns out it’s simpler than that:
</p>
        <p>
 
</p>
        <div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
          <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
              <span style="color: #0000ff">using</span> (HostingEnvironment.Impersonate()) </pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">{</pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> </pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
              <span style="color: #008000">//
access external resource as app pool account</span>
            </pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> </pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">}</pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> </pre>
            <!--CRLF-->
          </div>
        </div>
        <font color="#0f0f0f">
        </font>
        <p>
 
</p>
        <p>
The HostingEnvironment.Impersonate() will do the same thing that as a call to RevertToSelf().
</p>
        <p>
 
</p>
        <p>
If you like me and organise your data access calls into nice methods that perform
a discrete action such as:
</p>
        <div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
          <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
              <span style="color: #0000ff">public</span>
              <span style="color: #0000ff">static</span>
              <span style="color: #0000ff">void</span> DeleteUser(<span style="color: #0000ff">int</span> userID)</pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">{</pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> </pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
              <span style="color: #008000">//do
some database access</span>
            </pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> </pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">}</pre>
            <!--CRLF-->
          </div>
        </div>
        <p>
 
</p>
        <p>
You might be really loathed to wrap all these methods with the same code like:
</p>
        <div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
          <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
              <span style="color: #0000ff">public</span>
              <span style="color: #0000ff">static</span>
              <span style="color: #0000ff">void</span> DeleteUser(<span style="color: #0000ff">int</span> userID)</pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">{</pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"> </pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
              <span style="color: #0000ff">using</span>(HostingEnvironment.Impersonate())</pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">   {</pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
              <span style="color: #008000">//do
some database access</span>
            </pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">   }</pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">}</pre>
            <!--CRLF-->
          </div>
        </div>
        <p>
 
</p>
        <p>
        </p>
        <p>
        </p>
        <p>
Instead you might like to take a look at what a project such as <a href="http://www.postsharp.org/">PostSharp</a> can
offer:
</p>
        <p>
 
</p>
        <p>
          <em>"You can make your own custom attributes that will really add new behaviors to
your code! This is sometimes called <strong>aspect-oriented programming</strong> (AOP)
or <strong>policy injection</strong>."</em>
        </p>
        <p>
 
</p>
        <p>
This means that you can define your own attribute that will have code that will run
on any invocation of your code:
</p>
        <div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
          <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
              <span style="color: #0000ff">public</span>
              <span style="color: #0000ff">class</span> ImpersonateAttribute
: OnMethodInvocationAspect</pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">{</pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
              <span style="color: #0000ff">public</span>
              <span style="color: #0000ff">override</span>
              <span style="color: #0000ff">void</span> OnInvocation(MethodInvocationEventArgs
eventArgs)</pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">    {</pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
              <span style="color: #0000ff">using</span>(HostingEnvironment.Impersonate())</pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">        {</pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">            eventArgs.Proceed();</pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">        }</pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">    }</pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">}</pre>
            <!--CRLF-->
          </div>
        </div>
        <p>
        </p>
        <p>
          <font color="#0f0f0f">
          </font> 
</p>
        <p>
So our code then looks like this:
</p>
        <div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
          <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">[ImpersonateAttribute]</pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
              <span style="color: #0000ff">public</span>
              <span style="color: #0000ff">static</span>
              <span style="color: #0000ff">void</span> DeleteUser(<span style="color: #0000ff">int</span> userID)</pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">{</pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
              <span style="color: #008000">//do
some database access </span>
            </pre>
            <!--CRLF-->
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">}</pre>
            <!--CRLF-->
          </div>
        </div>
        <p>
        </p>
        <p>
          <font color="#0f0f0f">
          </font> 
</p>
        <p>
Much easier to maintain. Now every bit of code with this attribute will run as the
application pool account.
</p>
        <img width="0" height="0" src="http://httpcode.com/blogs/aggbug.ashx?id=961b0893-cebf-47e2-a608-9562136bcad4" />
      </body>
      <title>Application Pool Impersonation – Using AOP to build a better RevertToSelf()</title>
      <guid isPermaLink="false">http://httpcode.com/blogs/PermaLink,guid,961b0893-cebf-47e2-a608-9562136bcad4.aspx</guid>
      <link>http://httpcode.com/blogs/PermaLink,guid,961b0893-cebf-47e2-a608-9562136bcad4.aspx</link>
      <pubDate>Sat, 13 Jun 2009 01:16:09 GMT</pubDate>
      <description>&lt;p&gt;
By default SharePoint will use impersonation, so the web.config file will have the
setting:
&lt;/p&gt;
&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
&lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;identity&lt;/span&gt; &lt;span style="color: #ff0000"&gt;impersonate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="true"&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font color="#0f0f0f"&gt;&lt;/font&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
This means that if you try and connect to a SQL server database from say a custom
web part, the connection will appear to SQL server as the user that requested the
page. This is very useful if you care about the actual user, so for example if the
database has permissions set based on this assumption. 
&lt;/p&gt;
&lt;p&gt;
However it is often useful to have just the application pool account connect to the
SQL Server database or you may wish to give the application pool account permissions
to connect to active directory but not every user. 
&lt;/p&gt;
&lt;p&gt;
It this case you will need to impersonate the application pool account. There is a
bit of code floating around the web that uses P/Invoke to call ReverToSelf() from
the advapi32.dll. It turns out it’s simpler than that:
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
&lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; (HostingEnvironment.Impersonate()) &lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #008000"&gt;//
access external resource as app pool account&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;font color="#0f0f0f"&gt;&lt;/font&gt; 
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
The HostingEnvironment.Impersonate() will do the same thing that as a call to RevertToSelf().
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
If you like me and organise your data access calls into nice methods that perform
a discrete action such as:
&lt;/p&gt;
&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
&lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; DeleteUser(&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; userID)&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #008000"&gt;//do
some database access&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
You might be really loathed to wrap all these methods with the same code like:
&lt;/p&gt;
&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
&lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; DeleteUser(&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; userID)&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;   &lt;span style="color: #0000ff"&gt;using&lt;/span&gt;(HostingEnvironment.Impersonate())&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;   {&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;      &lt;span style="color: #008000"&gt;//do
some database access&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;   }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
Instead you might like to take a look at what a project such as &lt;a href="http://www.postsharp.org/"&gt;PostSharp&lt;/a&gt; can
offer:
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;em&gt;"You can make your own custom attributes that will really add new behaviors to
your code! This is sometimes called &lt;strong&gt;aspect-oriented programming&lt;/strong&gt; (AOP)
or &lt;strong&gt;policy injection&lt;/strong&gt;."&lt;/em&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
This means that you can define your own attribute that will have code that will run
on any invocation of your code:
&lt;/p&gt;
&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
&lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; ImpersonateAttribute
: OnMethodInvocationAspect&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; OnInvocation(MethodInvocationEventArgs
eventArgs)&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        &lt;span style="color: #0000ff"&gt;using&lt;/span&gt;(HostingEnvironment.Impersonate())&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        {&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;            eventArgs.Proceed();&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font color="#0f0f0f"&gt;&lt;/font&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
So our code then looks like this:
&lt;/p&gt;
&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
&lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;[ImpersonateAttribute]&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; DeleteUser(&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; userID)&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;   &lt;span style="color: #008000"&gt;//do
some database access &lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font color="#0f0f0f"&gt;&lt;/font&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Much easier to maintain. Now every bit of code with this attribute will run as the
application pool account.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://httpcode.com/blogs/aggbug.ashx?id=961b0893-cebf-47e2-a608-9562136bcad4" /&gt;</description>
      <comments>http://httpcode.com/blogs/CommentView,guid,961b0893-cebf-47e2-a608-9562136bcad4.aspx</comments>
      <category>code</category>
      <category>Sharepoint</category>
    </item>
    <item>
      <trackback:ping>http://httpcode.com/blogs/Trackback.aspx?guid=fcd65607-a907-4512-8818-d20c4200806a</trackback:ping>
      <pingback:server>http://httpcode.com/blogs/pingback.aspx</pingback:server>
      <pingback:target>http://httpcode.com/blogs/PermaLink,guid,fcd65607-a907-4512-8818-d20c4200806a.aspx</pingback:target>
      <dc:creator>Daniel Pollard</dc:creator>
      <wfw:comment>http://httpcode.com/blogs/CommentView,guid,fcd65607-a907-4512-8818-d20c4200806a.aspx</wfw:comment>
      <wfw:commentRss>http://httpcode.com/blogs/SyndicationService.asmx/GetEntryCommentsRss?guid=fcd65607-a907-4512-8818-d20c4200806a</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I came across an interesting problem recently deploying an ASP.NET application to
the ISV directory in CRM 4, the ASP.NET application was working fine using the Cassini
web server inside of Visual Studio, but when it was deployed to the ISV directory
on the CRM server it failed to run.
</p>
        <p>
Basically any postback caused the web forms to loose all it’s current data, so things
like dropdown lists would end up blank.
</p>
        <p>
It was pretty obvious that this was caused by ViewState being turned off.
</p>
        <p>
The default web.config file of CRM looks like:
</p>
        <p>
 
</p>
        <div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
          <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
              <span style="color: #0000ff">&lt;</span>
              <span style="color: #800000">pages</span>
              <span style="color: #ff0000">buffer</span>
              <span style="color: #0000ff">="true"</span>
              <span style="color: #ff0000">enableSessionState</span>
              <span style="color: #0000ff">="false"</span>
              <span style="color: #ff0000">enableViewState</span>
              <span style="color: #0000ff">="false"</span>
              <span style="color: #ff0000">validateRequest</span>
              <span style="color: #0000ff">="false"</span>
              <span style="color: #0000ff">/&gt;</span>
            </pre>
            <!--CRLF-->
          </div>
        </div>
        <p>
        </p>
        <p>
 
</p>
        <p>
Since the ISV directory inherits from this web.config file, all the applications in
the ISV directory will also have viewstate disabled.
</p>
        <p>
 
</p>
        <p>
So just add the following line to your web.config file in the ISV directory:
</p>
        <p>
 
</p>
        <div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
          <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
            <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
              <span style="color: #0000ff">&lt;</span>
              <span style="color: #800000">pages</span>
              <span style="color: #ff0000">enableViewState</span>
              <span style="color: #0000ff">="true"</span>
              <span style="color: #0000ff">/&gt;</span>
            </pre>
            <!--CRLF-->
          </div>
        </div>
        <p>
 
</p>
        <p>
Personally I don’t really see the need to enable viewstate, in most cases it isn’t
needed if the programmer understands it’s purpose, but sometimes your just trying
to deploy code that someone else wrote.
</p>
        <img width="0" height="0" src="http://httpcode.com/blogs/aggbug.ashx?id=fcd65607-a907-4512-8818-d20c4200806a" />
      </body>
      <title>CRM 4 – Viewstate for ISV Directory</title>
      <guid isPermaLink="false">http://httpcode.com/blogs/PermaLink,guid,fcd65607-a907-4512-8818-d20c4200806a.aspx</guid>
      <link>http://httpcode.com/blogs/PermaLink,guid,fcd65607-a907-4512-8818-d20c4200806a.aspx</link>
      <pubDate>Sat, 13 Jun 2009 00:46:28 GMT</pubDate>
      <description>&lt;p&gt;
I came across an interesting problem recently deploying an ASP.NET application to
the ISV directory in CRM 4, the ASP.NET application was working fine using the Cassini
web server inside of Visual Studio, but when it was deployed to the ISV directory
on the CRM server it failed to run.
&lt;/p&gt;
&lt;p&gt;
Basically any postback caused the web forms to loose all it’s current data, so things
like dropdown lists would end up blank.
&lt;/p&gt;
&lt;p&gt;
It was pretty obvious that this was caused by ViewState being turned off.
&lt;/p&gt;
&lt;p&gt;
The default web.config file of CRM looks like:
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
&lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;pages&lt;/span&gt; &lt;span style="color: #ff0000"&gt;buffer&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="true"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;enableSessionState&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="false"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;enableViewState&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="false"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;validateRequest&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="false"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Since the ISV directory inherits from this web.config file, all the applications in
the ISV directory will also have viewstate disabled.
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
So just add the following line to your web.config file in the ISV directory:
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
&lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;pages&lt;/span&gt; &lt;span style="color: #ff0000"&gt;enableViewState&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="true"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Personally I don’t really see the need to enable viewstate, in most cases it isn’t
needed if the programmer understands it’s purpose, but sometimes your just trying
to deploy code that someone else wrote.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://httpcode.com/blogs/aggbug.ashx?id=fcd65607-a907-4512-8818-d20c4200806a" /&gt;</description>
      <comments>http://httpcode.com/blogs/CommentView,guid,fcd65607-a907-4512-8818-d20c4200806a.aspx</comments>
      <category>CRM</category>
      <category>setup</category>
    </item>
  </channel>
</rss>
