News


If like me, you have to turn your hand to design every now and then, you might find some of these useful:

 

Fonts

Free for commercial use fonts.

http://www.fontsquirrel.com/

 

Colours

A very cool flash based colour picker.

http://kuler.adobe.com/#create/fromacolor

Another colour scheme design – all HTML this time…

http://colorschemedesigner.com/

 

Icons

A library of icons with various licences.

http://www.iconlet.com/

 

Hope you find some of these useful… leave a comment if you have any other suggestions.

kick it on DotNetKicks.com


I’m not a big fan of #region, I use it occasionally but generally try to avoid it. It’s always frustrating to open a code file and be presented with nothing but collapsed regions – sure, it looks neat (and lets face, more than a few programmers are a little OCD) but I want to see the code, that’s why I opened the file in the first place!

Don’t worry, I’m not going off on a rant, I just want to direct you to a much more level headed explanation of The Problem With Code Folding. I couldn’t agree more.



I saw this on Julie Lerman’s blog and had to give it a go. I’m quite relieved to say:

54% Geek

I’m glad to be a bit geeky, but wouldn’t want to score too high!!!



I ran into a page on the Microsoft web site that was showing a compile error. It’s fairly unusual but the developers over at MS are only human and they are going to make mistakes sometimes. What I thought was particularly interesting was that the CustomErrors option in their web.config was set to Off, showing the full source code of the page.

The page is at http://lab.msdn.microsoft.com/ but I’m sure they will have fixed it by the time you read this so here is a screen shot.

 

MicrosoftPage

 

I wish I could report some shocking fact gleaned from their source code, but it was all mundane C#…



I spent ages this morning trying to find a way to determine if a user has permission to access a page before navigating to it. I knew it was possible, the SiteMapProvider has a property called “SecurityTrimmingEnabled” that hides pages that the user cannot access.

In the end I found a really useful object called UrlAuthorizationModule in the System.Web.Security namespace that has a method called CheckUrlAccessForPrincipal(). Pass in the url and get a Boolean return value indicating whether the resource is accessible. Easy when you know how!



A while ago (in fact, it was two mobile phones ago) I had a non-touch phone. Most apps worked well but every now and again I wished I had a point and click interface. As I was trying to scroll around a particularly large web page I had an idea: What if the phone screen was a window and you scrolled it around by moving the phone itself? Almost all phones have a camera on the back, surely it could be used in the same way as an optical mouse to track movements on a surface. All you need to do is put your phone on the table and you could look at a large document as though it was stuck to the table itself!

I’ve tried to illustrate how it would work with the image of the bing home page below, except you would only be able to see the page through the phones screen (obviously).

 

PhoneAsMouse

 

I’m about to get a new phone and I’m going back to using a keypad (in fact I’m getting the Samsung from the image above). This has reminded me of my idea from years ago so I thought I’d search to see if anything like it has been done. It seems somebody has turned their Nokia mobile into a Bluetooth mouse for their pc, so it must be possible – come on Microsoft, this would be a great feature in Windows Mobile 7!!!

kick it on DotNetKicks.com



Having written about the new features planned for VB.NET 10, I’ve been meaning to write about what to expect in ASP.NET 4.0, specifically what is happening around webforms. Well, Mike Ormond has written an excellent blog post on just that subject so I like to him instead:

ASP.NET 4.0 Webforms Enhancements

Enjoy!



Rather than the productive day of web development I had planned I spent most of this morning trying to figure out why Visual Studio’s built in web server, webdev.webserver.exe, would not respond when I ran the web project.

At first I though it was the project so I checked the config, rebuilt it, and restarted Visual Studio – no luck.

Next I tried opening another project, that didn’t work either so I though it was something on my machine. Time to look at the anti-virus and firewall, but after disabling everything it still wasn’t working.

It was at this point I got a Skype message from one of my clients - “Do you know why the Development Web Server in Visual Studio might be broken?”. Ah ha! So it wasn’t just my machine. That must mean it was an update Microsoft pushed out.

Google didn’t have any likely looking results on the first couple of pages but a search of twitter returned a tweet from a developer in Prague (written in Czech) with the words Defender and webdev.webserver.exe in it. A quick pass through Google’s translation tool and I had the gist of the message: An update to Windows Defender has broken the mapping between localhost and the loopback address (127.0.0.1). All I had to do was run my project and replace localhost with 127.0.0.1 in the address bar and everything was fine.

I’ve wasted too much time on this as it is, so I’m going to stick with the workaround for now and I’ll update this post when I figure out the solution (unless you know the answer, in which case please post a comment!)

EDIT: Thanks to Dragan who dug a little deeper and found that it is the hosts file that is being modified. As he says in his comment, open C:\Windows\System32\drivers\etc\hosts and replace the ::1 next to localhost with 127.0.0.1

kick it on DotNetKicks.com


Attributes are a great way to communicate some extra information about a class, method or property and the debugger looks for a few different attributes to determine the way it behaves while you are debugging code. Let’s take a look at the attributes that are used to control how the data tips display an object’s value.

Imagine you had a simple customer class. Here is a screenshot of it at runtime:

 

Debugger with no attributes

As you can see, the debugger is showing the public properties and the private fields that are used to store them. There are times that can be extremely useful, but in this case it’s just noise. We can simplify the display using the DebuggerBrowsable attribute with a parameter of DebuggerBrowsableState.Never

<DebuggerBrowsable(DebuggerBrowsableState.Never)> _
Private _Name As String

Having added the attribute to both the _Name and _Orders fields, this is what we see in the data tip:

CustomerBrowsableAttributesThe next thing I want to do is change what is displayed when we first hover over the class. Currently the debugger displays the type name ( DebuggerDemo.Main.Customer), but it would be much more useful it we saw the customer name. The DebuggerDisplay attribute applied at the class level can be used to display any string, including the values of properties or the results of method calls. The Name property could be displayed like this:

<DebuggerDisplay("Customer: {Name}")> _
Public Class Customer

The curly brackets are used to identify expressions within the literal string. Applying the above attribute to the Customer class gives a much more useful summary of the object:

CustomerDisplayAttribute

The quotation marks that are automatically applied to any string value can be removed by adding nq to the expression, i,e,:

<DebuggerDisplay("Customer: {Name,nq}")>

Be careful, if you put a space after the comma it won’t work! The DebuggerDisplay attribute can be used to display complex expressions if needed, for example, we might want to add some details about the customer’s orders to the data tip:

<DebuggerDisplay("Customer: {Name,nq} ({If(Orders.Count>0, Orders.Count.ToString(), ""no""),nq} orders)")> 

(This should all be on one line, but I haven’t added underscores because they would be mid-string, and that would get too confusing).

The above attribute would make our customer data tip appear like this:

CustomerDisplayAttribute2The final thing I want to demonstrate uses the  DebuggerBrowsable attribute again, except this time it is with the DebuggerBrowsableState.RootHidden parameter. By decorating the Orders property with this attribute we can auto-expand the list of orders (or more accurately, hide the root and display all the children instead). This is the code I added:

<DebuggerBrowsable(DebuggerBrowsableState.RootHidden)> _
Public Property Orders() As List(Of Order)

And this is the result:

 CustomerBrowsableAttribute2

Of course, I also added a DebuggerDisplay attribute to the Order class so we see information about each order. That was achieved with this attribute:

<DebuggerDisplay("Order: {Product,nq} x {Qty}")> _
Public Class Order

You are not going to want to apply these attribute to every class you write, but for some of your main class that you are debugging with all the time it is worth the effort. In fact, there have been times I’ve added a DebuggerDisplay attribute to a class just to debug it, removing it when I was finished!

kick it on DotNetKicks.com


I need sample / test data all the time. When ever I build an application for a client it is useful for testing and demonstrating, when I teach a course it's always useful to have a demo database on hand (I'm a bit bored of Northwind and Pubs).

Over the years I've collected all sorts of useful sample data, like real surnames, first names and place names. All I've lacked is something to randomly pick from those lists to create a dataset ready to import (in the format I need at the time).

During some free time I had recently I decided to build a generator, but I wanted something really flexable, so what I built uses a template to determine what the output should look like. For example, if all you wanted was a CSV list of names you could do something like this:

{title}, {firstname}, {lastname}

If you wanted to insert those names into a database, then maybe generating the SQL insert statements would be more useful:

INSERT INTO People (Title, FirstName, LastName) VALUES ("{title}", "{firstname}", "{lastname}")

You can also insert numbers, guids, values picked from lists, patterns of characters, greeking text and of course real UK streetnames, towns and counties (with random but real looking postcodes).

If you think this will be as useful to you as it is to me, you can find it here:

http://www.dotnettech.net/Tools/TestData

Edit: Thanks to Eric Nelson for linking to the test data generator, both from the MSDN Flash newsletter and his own blog.

kick it on DotNetKicks.com