Digital Thoughts : .NET 2.0 related to software/web development using .NET 2.0en-GBCommunityServer 2.0 (Build: 60217.2664)FlexWiki 2.0, 04 May 2006 14:25:00 GMT31eb02f0-ccfc-4712-8b04-2b5c7351f0c8:714Derek Lakin0 happened quite a while back now and even more progress has been made, but I still think it's worth mentioning. Thanks to the herculean efforts by <a href="#topofpage">Craig Andera</a>, FlexWiki has been branched in CVS to give a new branch that is built using .NET 2.0.<br><blockquote>One of the things I've been working on - a little at a time, usually about half an hour a day - is a fairly extensive rewrite of <a href="#topofpage">FlexWiki</a>. We're calling it <a title="FlexWiki" href="#topofpage">FlexWiki</a> 2.0, and not coincidentally, it involves an upgrade to .NET/ASP.NET 2.0.<br></blockquote><blockquote>This partial rewrite was driven by the desire to give <a title="FlexWiki" href="#topofpage">FlexWiki</a> a better authorization model. I still haven't even started on that part of it - first I had to untangle the existing caching code from the storage engine, and separate out a bunch of special processing that deals with something called "backing topics". Don't ask.<br></blockquote>Many thanks to Craig for his continued involvements and effort on the FlexWiki project. Once 2.0 finally hits the streets I expect to be getting more involved with some of the mods I was working on a while ago. I felt that it wasn't worth committing them while Craig was doing such a major re-write.<br><img src="/aggbug_PostID_714.html" width="1" height="1">SoftwareWeb.NET 2.0Extending the Atlas Wiki Part I - Adding Email Support, 29 Nov 2005 12:48:00 GMT31eb02f0-ccfc-4712-8b04-2b5c7351f0c8:592Derek Lakin0<P><A href="#topofpage"><IMG alt="Atlas Wiki Registration Form" src="" align=left border=0></A>I just posted <A href="#topofpage">an article</A> over on <A href="#topofpage">Bill's Baby</A>&nbsp;that describes how to add email support to the <A href="#topofpage">ASP.NET "Atlas" Wiki</A>. It describes how to get emails sent to new users when the register and how to notify an administrator when new users have registered.</P> <P>The article includes listings for all the code you'll need to accomplish these tasks and forms the basis of a series of articles that will extend and enhance the Atlas Wiki.</P> <P>Future articles in the series will focus as much as possible on the actual Atlas parts of the wiki, if nothing else to help me get a better understanding of what it is and what it can do.</P><img src="/aggbug_PostID_592.html" width="1" height="1">Web.NET 2.0Uninstalling the Betas, 28 Nov 2005 10:35:00 GMT31eb02f0-ccfc-4712-8b04-2b5c7351f0c8:590Derek Lakin0 you haven't yet installed the release version of one of the Visual Studio 2005 editions then you may find <A href="">this Microsoft&nbsp;page</A>&nbsp;particularly useful as it includes a link to an auto-uninstall tool for automatically removing any previous beta releases. It also includes manual uninstall instructions.<img src="/aggbug_PostID_590.html" width="1" height="1">SoftwareWeb.NET 2.0RegEx Visualizers for Visual Studio 2005, 28 Nov 2005 10:19:00 GMT31eb02f0-ccfc-4712-8b04-2b5c7351f0c8:589Derek Lakin0<P><A href="#topofpage">Roy Osherove</A> (author of the Regulator) has just released a <A href="#topofpage">Regex Debug Visualizers kit for Visual Studio 2005</A>.</P> <BLOCKQUOTE dir=ltr> <P>Visual Studio allows creating "Debug Visualizers" for all types in .NET framework as well as custom types.<BR>You can find such visualizers for Datasets, strings and XML. There wasn't one for Regular expressions, until now.<BR>These visualizers allow you to "visualize" the following types:</P> <P>System.String<BR>System.Text.RegularExpressions.Regex<BR>System.Text.RegularExpressions.Match<BR>System.Text.RegularExpressions.MatchCollection</P></BLOCKQUOTE> <P dir=ltr>I generally prefer to use <A href="#topofpage">Expresso</A>, but I do have Regulator installed too. Personally I've had more consistent results with Expresso and I like the way it keeps a history of all your regex changes, but I'm keen to see how Regulator 3.0 pans out.</P><img src="/aggbug_PostID_589.html" width="1" height="1">Software.NET 2.0Caching in Windows Applications, 24 Nov 2005 09:54:00 GMT31eb02f0-ccfc-4712-8b04-2b5c7351f0c8:586Derek Lakin1<P>I've often heard that you can use the ASP.NET caching features&nbsp;provided by&nbsp;the .NET Framework in Windows applications, but never tried it. Well, today I read <A href="#topofpage">a post by the great Scott Hanselman</A>&nbsp;that confirms it:</P> <BLOCKQUOTE dir=ltr> <P>&nbsp;I also started a conversation on a list server and here's what came of that:</P> <P dir=ltr><A href="#topofpage">Rob Howard said:</A> </P> <BLOCKQUOTE dir=ltr> <P><EM>Yes, it's fairly common (and easy) to do. You just have to include a reference to the System.Web assembly in non-web applications; which may have led to your "creep out" – for what it’s worth it used to do the same to me&nbsp;:)</EM><EM>&nbsp;<BR></EM><EM>FWIW, I believe (from memory) the recommended way you grab a reference outside of a web application is:<BR></EM><EM>using System.Web;<BR></EM><EM>using System.Web.Caching;<BR></EM><EM>…<BR></EM><EM>Cache cache = HttpRuntime.Cache;<BR></EM><EM>&lt;snip&gt;...the Cache is just too important of a feature to only belong to ASP.NET.</EM></P></BLOCKQUOTE></BLOCKQUOTE> <P dir=ltr>It seems that the biggest obstacle most people come across is a psychological one of actually adding a reference to System.Web and System.Web.Caching! Once you can get over that then you have access to the great lightweight caching features, including the cache expiration stuff.</P> <P dir=ltr>One commenter did suggest that you could always use the <A href="#topofpage">Enterprise Library Caching Block</A> from the <A href="#topofpage">Microsoft patterns &amp; practices website</A>, but I would tend to agree with Scott: there's just too much going on with the caching block and probably a bit too heavyweight for a lot of applications.</P> <P dir=ltr>Now I can't wait to try this out in my next Windows application!</P><img src="/aggbug_PostID_586.html" width="1" height="1">SoftwareWeb.NET 2.0More Free Stuff!, 14 Nov 2005 11:26:00 GMT31eb02f0-ccfc-4712-8b04-2b5c7351f0c8:578Derek Lakin0<P>Continuing the tradition of signingup for free developer goodies here's a post about more free stuff. Over at the Component Factory the <A href="#topofpage">Krypton Toolkit</A>&nbsp;has been released. Just go to the <A href="#topofpage">Downloads</A> link and enter your email address to receive instructions. The Krypton Toolkit is a .NET 2.0 user&nbsp;interface control library for Windows Forms with full support for Visual Studio 2005 that is free for commercialuse.</P> <P>In addition to this they are also <A href="#topofpage">offering a free license</A> and 12 months subscription to Crownwood Software's <A href="#topofpage">DotNetMagic</A>&nbsp;simply by blogging about the Krypton Toolkit release.</P><img src="/aggbug_PostID_578.html" width="1" height="1">BlogSoftware.NET 2.0How do I Create a Web Service in Visual Studio 2005, 10 Nov 2005 11:40:00 GMT31eb02f0-ccfc-4712-8b04-2b5c7351f0c8:575Derek Lakin0<P>If you want to create a web service in Visual Studio 2005, you will need to choose File &gt; New &gt; Web Site and choose "ASP .NET Web Service" from the templates.</P> <P>Having moved the web site stuff into this new place in the first place, I guess it makes sense that web service projects would be in the same place, it's just a little disorienting for the uninitiated.</P><img src="/aggbug_PostID_575.html" width="1" height="1">Web.NET 2.0Skinnable Script Control Update, 01 Nov 2005 20:58:00 GMT31eb02f0-ccfc-4712-8b04-2b5c7351f0c8:574Derek Lakin0<P>A while back I blogged about a <a href="/archive/2005/10/05/554.html">skinnable script control</A> to provide access to theme-specific script includes. Well, after some recent testing I realised that it wasn't generating urls that worked in all circumstances.</P> <P>Most of the ASP.NET Web Controls (such as the Image control) allow you to specify a URL as being application root relative by using the tilde character '~'. After a little digging in to the source code using Reflector I quickly saw that using base.ResolveUrl (from the System.Web.UI.Control) is what controls like Image use, so a quick change to the render code means I can put a tilde at the start of the script location and pass it to base.ResolveUrl to generate a script location that works all the time because it's relative to the root of the application.</P><img src="/aggbug_PostID_574.html" width="1" height="1">Web.NET 2.0Are Microsoft Dumbing Down Web Development?, 13 Oct 2005 09:24:00 GMT31eb02f0-ccfc-4712-8b04-2b5c7351f0c8:567Derek Lakin1<P>It seems to me that lots of features have been "simplified" (I prefer the term dumbed down ;)) in developing web sites under Visual Studio 2005. The following are examples that I've found so far:</P> <P>Web site projects do not and cannot have a default namespace specified in the project properties and in fact by default pages and controls are not created in a namespace. You can put your page/control classes inside namespaces, but you have to manually update the page/control directive. Interestingly this is in violation of one of the Design Guidelines (CA1050) enforced by the Code Analysis tool, which states that all public or protected types should be declared inside a namespace to prevent naming collisions and to organise related types in an object hierarchy, but this violation is not reported by the Code Analysis tool in web site projects.</P> <P>This leads me on nicely to the next point. For Web site projects you can only specify whether or not you want Code Analysis to be run, you cannot customise the rules in the same way as you can for other projects.</P> <P>And also on the topic of declaring types in namespaces; if you use the new Profile features provided in ASP.NET 2.0 you get a class called ProfileCommon automatically generated for you which provides strongly typed access to the profile properties that you specify in web.config. However this class is not declared inside a namespace and&nbsp;does generate a CA1050 violation.</P> <P>One more thing before I go: server controls created on pages and in user controls used to be declared in the code behind as protected members, and event handling used to be registered in the OnInit method. This is no longer the case. Event handling is declared in the control declaration in the aspx page and server controls aren't explicitly declared they "just exist". I'm all for writing less code, but I'm not convinced this is a step forward yet.</P><img src="/aggbug_PostID_567.html" width="1" height="1">Web.NET 2.0Cool Refactoring, 08 Oct 2005 16:49:00 GMT31eb02f0-ccfc-4712-8b04-2b5c7351f0c8:565Derek Lakin0<P>Visual Studio provides some really good refactoring tools, such as renaming, so that if you rename a class for example a smart tag pops up and allows you to rename and references.</P> <P>Today, however, I noticed that this is all done automatically if you rename the file that the class is contained in!! Cool <IMG src="/file///C/Program20Files/imeem/resources/smiley_veryhappy.png" align=absMiddle></P><img src="/aggbug_PostID_565.html" width="1" height="1">Software.NET 2.0Post-dated Posts, 05 Oct 2005 15:46:00 GMT31eb02f0-ccfc-4712-8b04-2b5c7351f0c8:561Derek Lakin2 for the recent flurry of post-dated posts, but I had been blogging them on one of my <A href="#topofpage">imeem</A> <A href="#topofpage">blogs</A> and decided that I should cross-post them here too (as this site gets much more traffic). There won't be any more post-dated posts, but you can rest assured that there will be plenty more .NET 2.0 posts!<img src="/aggbug_PostID_561.html" width="1" height="1">Blog.NET 2.0Skinnable/Themeable Controls and Script Includes, 05 Oct 2005 15:02:00 GMT31eb02f0-ccfc-4712-8b04-2b5c7351f0c8:554Derek Lakin1<P>Yesterday I moved on from the back-end logic and data access of my pet project to the front-end stuff and so quickly introduced myself to MasterPages and Skins/Themes.</P> <P>I had already produced the design for the site and so it was a fairly simple process to create a Theme based on the design. </P> <P>My first obstacle was one of understanding and documentation interpretation. The whole point of themes is that you can switch from one to another with relatively little effort (if you define it in the pages element in web.config you only have to change it in one place) and so when I wanted to use an image from the theme in a page I figured it would be as easy as includin an &lt;asp:Image /&gt; control and specifying the relevant ImageUrl. The documentation seemed to back me up on this point as in the <EM><A href="#topofpage">ASP.NET Themes and Skins Overview</A></EM> in the <EM>Theme Graphics and Other Resources</EM> section it states:</P> <BLOCKQUOTE dir=ltr> <P>"<EM>Themes can also include graphics and other resources, such as script files or sound files. For example, part of your page theme might include a skin for a TreeView control. As part of the theme, you can include the graphics used to represent the expand and collapse buttons.</EM></P> <P><EM>Typically the resource files for the theme are in the same folder as the skin files for that theme, but they can be elsewhere in the Web application, in a subfolder of the theme directory for example. To refer to a resource file in a subfolder of the theme directory, use a path like the one shown in this Image control skin:</EM></P> <P><EM><FONT face="Courier New">&lt;asp:Image runat="server" ImageUrl="ThemeSubfolder/filename.ext" /&gt;</FONT></EM>"</P></BLOCKQUOTE> <P>At first reading this would seem to infer that my initial assumption was correct and that to put a theme-based image on a page I simply need to add the above &lt;asp:Image /&gt; type element specifying the subfolder (if required) and filename within the theme folder as the ImageUrl. However, my understaning was wrong (and thanks to <A href="#topofpage">Craig Andera</A> for correcting my understanding), what the documentation is trying to say is that you create a .skin file with the relevant &lt;asp:Image /&gt; control in it and specify the ImageUrl in there according to the theme subfolder and image filename. Then you just add the <FONT face="Courier New">&lt;asp:Image /&gt;</FONT> control to a themed page and set it's <FONT face="Courier New">SkinID</FONT> to match the <FONT face="Courier New">SkinID</FONT> in the .skin file.</P> <P>This approach allows you to tie the&nbsp;<FONT face="Courier New">&lt;asp:Image /&gt;</FONT>&nbsp;control with a specific ID to a specific image for <STRONG>this theme only</STRONG>, which is a much better idea. Subsequent themes might not name the image file the same or may not even have that specific image file in them.</P> <P>The next problem was that my site design uses a javascript include file to process&nbsp;certain &lt;div /&gt; elements to display <A href="#topofpage">rounded boxes</A>. This is, of course, theme specific and should also reside in the theme folder, but how do I get a script include from the theme folder? The <FONT face="Courier New">ClientScriptManager</FONT> class is the first port of call as this provides us with methods such as <FONT face="Courier New">RegisterStartupScript</FONT> and <FONT face="Courier New">RegisterClientScriptInclude</FONT>, which allow us to dynamically include script blocks (former) and script includes (latter). To make this work we need to get to the theme folder which is "/App_Themes/&lt;theme name&gt;/scripts/". We could just hack about in the <FONT face="Courier New">Page_Load</FONT> event handler and pull out the value of the <FONT face="Courier New">Theme</FONT> property to format a string to get the script location, but this feels all wrong. The following approach is much better (and thanks again to Craig for his help on this):</P> <P>First of all create a <FONT face="Courier New">UserControl</FONT> derived class with a <FONT face="Courier New">ScriptUrl</FONT> property&nbsp;that does nothing but register the script:</P> <BLOCKQUOTE dir=ltr> <P><FONT face="Courier New">ClientScriptManager csm = this.Page.ClientScript;<BR>string key = "cssCorners";<BR>Type type = this.GetType();</FONT></P> <P><FONT face="Courier New">if ((false == csm.IsClientScriptIncludeRegistered(type, key)) &amp;&amp; (this.ScriptUrl.Length &gt; 0))<BR>{<BR>&nbsp;&nbsp;&nbsp; string scriptLocation = string.Format("App_Themes/{0}/{1}", HttpUtility.UrlPathEncode(this.Page.Theme), HttpUtility.UrlPathEncode(this.ScriptUrl));<BR>&nbsp;&nbsp;&nbsp; csm.RegisterClientScriptInclude(type, key, scriptLocation);<BR>}</FONT></P></BLOCKQUOTE> <P>Then create a .skin file (or extend an existing one) that specifies that for a specific <FONT face="Courier New">SkinID</FONT> for our <FONT face="Courier New">UserControl</FONT>, where the script include is. Then you can either put an instance of the <FONT face="Courier New">UserControl</FONT> on the <FONT face="Courier New">MasterPage</FONT>, or just include it on pages that you need the script on. Then, if I change the theme and it doesn't use a script file I just don't specify the <FONT face="Courier New">UserControl</FONT> in that theme's skin file, or if it's a different script include, change the <FONT face="Courier New">ScriptUrl</FONT> in the new theme's skin file.</P><img src="/aggbug_PostID_554.html" width="1" height="1">Web.NET 2.0Debugging and Unit Testing, 30 Sep 2005 15:45:00 GMT31eb02f0-ccfc-4712-8b04-2b5c7351f0c8:560Derek Lakin0<P>I've written enough code to start debugging and unit testing now (no flaming about writing unit tests first, etc, please!). The Create Unit Tests feature is really nice. With virtually no effort at all you can set up unit tests to start exercising your code.</P> <P>One thing worth noting is that you can't have Code Coverage Analysis (which is very cool) enabled while your debugging tests.</P> <P>The main purpose of this particular post, though is to raise an eyebrow of confusion over the debugging facilities. For as long as I can remember I've been able to Step In, Step Out, Step Over and Run to Cursor whilst debugging (Visual C++ had this and Visual Studio .NET too). However, my beloved Visual Studio 2005 seems to have restricted this down to just Step Over and Run to Cursor.</P> <P>You can still set a breakpoint somewhere else and run to it, or find the method you want to step in to and choose run to cursor, but this is nowhere near as efficient or convenient as Step In and Step Out.</P> <P>I'm hoping I just haven't found the right menu, toolbar or keyboard shortcut yet.</P> <P><STRONG>Update:</STRONG> I just found them! You need to customise your toolbar/menu to do it, but they are there if you look hard enough. Another one of those things that I hope doesn't stay like this when it's released.</P><img src="/aggbug_PostID_560.html" width="1" height="1">SoftwareWeb.NET 2.0AssemblyFileVersionAttribute, 29 Sep 2005 15:44:00 GMT31eb02f0-ccfc-4712-8b04-2b5c7351f0c8:559Derek Lakin0<P>If you ever get all anal about your version numbers then you've probably played around with the AssemblyVersion and AssemblyFileVersion attributes in AssemblyInfo.cs.</P> <P>In Visual Studio .NET 2003 the AssemblyInfo.cs that you get by default just specifies the AssemblyVersion attribute and the comment above it tells you that you can either explicitly specify or you can specify major.minor.* which generates a build and revision for you.</P> <P>In Visual Studio 2005 the default AssemblyInfo.cs generated file adds the AssemblyFileVersion attribute aswell. This attribute is the one that is used by Win32 to report the verison and according to the documentation it does not accept wildcards (like AssemblyVersion does), but the comment remains the same.</P> <P>According to the <A href="#topofpage">docs</A>:</P> <BLOCKQUOTE dir=ltr> <P>"<EM>The file version is normally a string of four numbers, separated by periods, reflecting the major version number, minor version number, build number, and revision number; for example, "1.0.4309.00". If version is not in this format, a compiler warning occurs, and the results displayed in the file properties dialog are unpredictable. Wildcards are not supported.</EM>"</P></BLOCKQUOTE> <P>So you can have a generated AssemblyVersion, but not AssemblyFileVersion, however, if you exclude the AssemblyFileVersion (like VS .NET 2K3) then the value is set to the same as AssemblyVersion anyway.</P> <P>I'm sure somewhere you can change what you get as a default AssemblyInfo.cs, but I haven't found where yet. When I find it I'll set the CLSCompliant and SecurityAttribute permissions too as they both flag warnings when absent if you run a Code Analysis on your project.</P><img src="/aggbug_PostID_559.html" width="1" height="1">SoftwareWeb.NET 2.0Code Snippets, 29 Sep 2005 15:42:00 GMT31eb02f0-ccfc-4712-8b04-2b5c7351f0c8:558Derek Lakin0<P>Code Snippets are great! Just type '?' and then hit &lt;TAB&gt; and you can choose from the available snippets <EM>or</EM>&nbsp;you can right-click in the code editor and choose "Insert Snippet..." <EM>or</EM> you can type the abbreviation for a snippet and hit tab.</P> <P>Once you've inserted your snippet you can then just hit &lt;TAB&gt; to cycle through the fields you need to fill in. So far I've been using "prop" to insert a new private field with a matching public property (you can use "propg" to insert a read-only property).</P> <P>My personal preference is to prefix member variables with "<STRONG>this.</STRONG>" (partly because it provides a visual cue as to whether the variable is local or a member, but mostly because it's a quick way to get intellisense!) and to my delight I found that the snippets are just XML files with a .snippet file extension stored in \Microsoft Visual Studio 8\VC#\Snippets\1033\.</P> <P>It's a really simple modification to just change the template to add "this." in front of the right parts <IMG src="/file///C/Program20Files/imeem/resources/smiley_veryhappy.png" align=absMiddle> but in case you're too lazy too do it yourself I've included my modified version in my Code Snippets shared files here on imeem.</P> <P>There is a Snippet Editor available and it's an Open Source effort hosted on <A href="#topofpage">GotDotNet</A>:</P> <BLOCKQUOTE dir=ltr> <P>"<EM>Are you eager to produce your own Visual Basic Code Snippets but prefer not to think in terms of angle brackets? The Visual Basic Snippet Editor is a Windows Forms application with UI for creating, editing, testing VB code snippets. You can specify snippet code and metadata (e.g., title, author, description, keyboard shortcut), replacement variables, and referenced assemblies. You can preview your snippet as it will appear when inserted into the code window, and you can even test whether it will compile.</EM>"</P></BLOCKQUOTE> <P>Unfortunately, it seems to only work on the Beta 2 release of VS, but source code is provided so presumably I could re-compile and try again.</P><img src="/aggbug_PostID_558.html" width="1" height="1">SoftwareWeb.NET 2.0