Visual Studio 2005–Code Snippets

One of the new features that comes with Visual Studio 2005 is Code Snippets is the ability to create code snippets, small blocks of code that are easily reusable as you develop. Think of it as the developer’s cook book. Creating your own code snippets is quite easy, there’s even a code snippet for doing that.

You can use code snippets to type a short alias, and then expand it into a common programming construct. For example, the for code snippet creates an empty for loop. Some code snippets are surround-with code snippets, which enable you to select lines of code, then choose a code snippet which will incorporate the selected lines of code. For example, selecting lines of code then activating the for code snippet creates a for loop with those lines of code inside the loop block. Code snippets can make writing program code quicker, easier, and more reliable.

Some of the code snippets have logic built-in, for example the constructor code snippet: it knows the name of the class for which you’d like to generate a constructor. If you would like to create your own code snippets with more advanced functionality you have to take a look at the Function element in the Literal element of the code snippet.

There is a gallery of free code snippets: http://www.gotcodesnippets.com/

More information about code snippets found here.

ASP.NET 2.0–Web Resources and SharePoint

One of the many new features in ASP.NET 2.0 is called Web Resources. Basically this allows you to store resources like images, scripts and so on, in an assembly. You can do this by using the WebResource attribute. This attribute can be applied on assembly level like this

[assembly: WebResource("image1.jpg", "image/jpeg")]
[assembly: WebResource("help.htm", "text/html", PerformSubstitution=true)]

If you want to use any of your resources in an ASP.NET form (or user control):

<img alt="help image" src=&lt;% = WebResource("image1.jpg") %&gt; />

When the page is rendered the image will point to something like:

<img alt="help image" src=WebResource.axd?d=bZaDBpnwEO_aWezomeGuYatieDaddy/>

Many of the default ASP.NET 2.0 controls use this feature to store scripts and images, a good example is the TreeView control. If you want to use the same technique in SharePoint, for example when you want to run ASP.NET 2.0 user controls you will face an issue. The problem is that the ISAPI filter of SharePoint will try to process the request to WebResource.axd,so you won’t be able to retrieve any resources.

Quick Tip–Double-Click to Add .DLL to GAC

Found this really useful tip which allows you to quickly add your .DLLs to the GAC when you need to without having to run the gacutil every time.  Good for those of us who don’t want to deal with launching the command shell.

1. Copy and paste the following into notepad

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\dllfile\shell\gacutil\command]
@="c:\\windows\\Microsoft.NET\\Framework\\v1.1.4322\\gacutil.exe /i \"%1\""

2. Save the file as gacutil.reg

3. Double-click the file you just created to add it to the registry.

Now whenever you want to add a .dll to the GAC, just double-click the .dll file and it will automatically install it with the gacutil.exe tool/