Yes you can have your javascript style curly brace positioning if you really want to

Posted on: Thursday, 15 October 2009 18:00

This question came up on the forums the other day. Basically somebody wanted to change the auto formatting features of Visual Studio so that their curly braces didnt get pushed down on to their own lines every time they wrote the next line.

An example of how visual studio will auto-format your methods out of the box:

public bool IsEnabled()
{
  return true;
}

However the user wanted to keep the first curly brace on the same line as the method signature like:

public bool IsEnabled() {
  return true;
}

It's a matter of personal style. Personally I think it is less readable because it reduces the scanability of the code - you have to schwip your eyes over to the end of the method signature (which can be a variable length) to check where the start of the curly braces are.

Anyway I appreciate everyone has their preferences so this is how you set it up if you are excited about this same-line curly brace option:

  1. Click Tools | Options…
  2. Scroll down to the Text Editor node
  3. Expand the C# node
  4. Expand the Formatting node
  5. Click on the New Lines node
  6. You will see a list of options like in the image below which give you full control over when Visual Studio should put your open brace on a new line

newlinesforbraces

Visual Web Developer 2008 Users

You might be wondering if this option is available to you, or you might have tried to follow the tutorial above and found out you cant find the nodes I described?

Well it is possible to configure this in VWD 2008 - the only difference is that after step 1 you need to tick the little checkbox that says "Show all settings".

An easy way to keep your dev and live server urls in sync

Posted on: Wednesday, 14 October 2009 18:00

A common setup for your live server is to run your website on the root of the domain. By this I mean if you wanted to go to the homepage of your site you would type in

http://www.example.com/

When you are working on your dev copy of the site with Cassini on localhost (the built in dev web server) though you find your urls look more like

http://localhost:4865/YourProjectName/

If you're working purely with asp.net components in your site then you can always rely on the squiggly notation (called the tilde) to ensure your urls are mapped to what is called your "Application Root".

So you could have an <asp:Image> that has an ImageUrl attribute which looks like this:

<asp:Image runat="server" ID="Image1" ImageUrl="~/Images/thumb1.gif" />

And this would get turned into the proper url(either /Images/thumb1.gif or /YourProjectName/Images/thumb1.gif).

The trouble is that in most projects you need to use some links that don't mesh into the tilde enabled mapping systems such as the urls inside your CSS files - or even linking the CSS files into your template.

If all this is sounding like a familiar problem then this tip is for you. The trick we need to perform is to make Cassini run your dev website on the root of the localhost domain rather than in a subdirectory. That way a single url can be used on both your dev and live servers.

The steps are pretty simple:

  1. In the Solution Explorer window you select your Project node
  2. In the Properties window (press F4 if you can't see it) you change the "Virtual path" attribute from /ProjectName to /

The two windows look like this in Visual Studio 2008:

how-to-change-site-root

Shout it kick it on DotNetKicks.com

I didn't want you logged in! How to prevent new users being signed in with CreateUserWizard

Posted on: Tuesday, 13 October 2009 19:55

This one has come up twice in the past week as an unknown feature of the CreateUserWizard. I've seen developers performing complicated code-behind magic to try and prevent the user being logged in and others simply asking if its possible.
The default behaviour of the CreateUserWizard is that when it has created the user it logs that new user in.
You might not want this for a few reasons:
  1. You are in an admin panel and you don't open up your signup's to the public.
  2. You have some extra coding in place that sends out a verification email before they are let into the system
  3. You want to review the accounts by hand before you activate them
  4. Some other mysterious reason

Well the way to prevent it is to add the following attribute to your CreateUserWizard control:

LoginCreatedUser="False"

Its a simple as that - when the newly created user is created they are not logged in.

Further Reading


kick it on DotNetKicks.com

Sending An Email Using Telnet

Posted on: Thursday, 8 October 2009 18:12

Note: This was originally posted on a site that I used work on but its no longer online.  I still find this tutorial handy when I am testing mail out so I thought I would repost it here for easy access.

When I am setting up an external mail server for a client I sometimes find it useful to test it out by sending the raw commands via telnet. The process is pretty straight forward. I am going to run through it twice in this article depending on the reason you're here:

Getting telnet in Windows Vista

If you follow the tutorial below in vista you will hit a problem almost straight away - telnet is not installed by default in Windows Vista. I have written a separate guide explaining how to install telnet in Windows Vista.

I want to learn what it means

  1. Start off by clicking the Start button and selecting Run...

  2. Type telnet and press enter. Microsoft Telnet Client will start. It looks like a standard dos box.

  3. Type the following command, replacing mail.server.co.uk with the url or ip of your mail server.

    open mail.server.co.uk 25

    25 is the standard SMTP port. Press enter at the end and you will connect to your mail server. If this doesn't work then this is the first sign you have problems.

    Some things to check are:

    • Did you spell everything correctly?
    • Are you connected to the internet?
    • If you typed a domain, have you tried the IP?
  4. Next step is to introduce yourself to the mail server. Replace yourname with any string you like, its simply used to indentify the sending in the email servers logs.

    helo yourname
  5. Tell the mail server who is sending the email. Replace you@yourname.co.uk with your own email address. Many mail servers will let you get away with a fake email address here, but if you are testing then I would recommend using a real one.

    MAIL FROM: you@yourname.co.uk
  6. Next you have to give the destination email address. Replace them@server.co.uk with your target address.

    RCPT TO: them@server.co.uk
  7. To send the body of your message you start off with a DATA command followed by enter. The response from this command will tell you how to end your message. Its almost always a full stop (.) on its own on a new line, but you should note this down.

  8. Type your message.

  9. End the message with the command you were instructed to in step 7 (probably a .).

  10. At this point your email address has been sent. If you want to send another message then you should start over. If not then its good practice to close your connection gracefully by issuing the QUIT command.

I just need reminding

If you have used telnet before and know the basics but just need reminding of the details then this quick reference guide should get you through with the minimum of hassle.

open mail.server.co.uk 25
HELO unique-identifier
MAIL FROM: you@yourcompany.co.uk
RCPT TO: them@server.co.uk

DATA
type your message here
. [or whatever identifier you are told to use after DATA]
QUIT
  

If any of these commands don't make sense then hop back up to the top of the page and read the full explanation!

How to install telnet in Windows Vista

Posted on: Wednesday, 7 October 2009 22:09

This is just a quick little tutorial which walks you through the steps to install telnet in Windows Vista as its not there by default.

It was written to accompany another upcoming tutorial I am working on but if you just landed here from a search engine then I guess its just as handy!

Is telnet already installed?

Before you follow this you better check you haven't already installed it and forgotten!

  1. Press Start Key on the keyboard and the R key together
  2. Type telnet into the run dialog
  3. Press enter

If you see a message that says "Windows cannot find 'telnet'. Make sure you typed the name correctly, and then try again." with an OK button then press OK and carry on with this tutorial.

Installing telnet

  1. Click the Start orb
  2. Choose Control Panel
  3. In the top right corner search box type "feature"
  4. Click the link that says "Turn Windows features on or off"
  5. Wait a short while for Windows to figure out which features you already have turned on
  6. Scroll down to the entry "Telnet Client"
  7. Tick the checkbox
  8. Click OK
  9. Wait another short while
  10. When its done you can close the control panel.

Features I Want To See In Asp.Net 4.0

Posted on: Sunday, 4 October 2009 12:57

I know this is probably a bit late in the pipeline now but I just wanted to jot down some features that I want to see in the next version of asp.net.

Visual Studio

  • recent Projects actually showing recent projects, like the last 8 projects I opened, and let me delete them from the list at will
  • make the RSS feed work in the start page!
  • integrate an easy to use feature into vs that lets me compile user controls into assemblies and hook them into other projects without having to jump through hoops of dodgy assembly names, stub files, registering items web.config, msbuild steps, and all the trouble.
  • give me a Dreamweaver quality site-sync to upload my files (the one in vwd 2008 cant connect to my server for some reason, it worked in vwd 2005 though it wasn't as good as Dreamweaver)

ASP.NET

  • fix this bug that prevents us from nesting templates in usercontrols
  • extend usercontrols to support more of the server control attributes like the ToolBoxData, type converters, etc OR
  • give server controls a design surface
  • add an "add to default sitemap" checkbox in the add new item dialog so I dont forget to put my pages in my .sitemap file
  • don't make me use lines like <@ MasterType VirtualPath="~/Templates/Main.master" %> in every content page that I want to access the master page.

MSDN

  • Add some documentation which explains the proper way to do SitemapPathResolve (see community content section) without crashing your server.

Platform Installer

  • fix the bug that occurs when you want to install sql 2008 over 2005 - the first time I wanted to use it and it force me to go back to the old school!

Change the default OS on a dual boot system

Posted on: Saturday, 3 October 2009 22:41

I have Windows 7 RC1 installed as well as Windows Vista. Up until a few minute ago I had been frantically hitting F8 every morning when I turned my pc on to stop it booting into Windows 7.

Windows 7 seems like a great system but I haven't installed all my programs and made a commitment to it. Plus I need to get a new sound card for it.

To change the default operating system is quite easy these days (if i recall correctly back in the day you would have had to edit a boot.ini file by hand and hope you got the syntax right)

This guide is for Windows Vista.

  1. Open up the "System" panel using one of these methods
    1. Click start, right click on your Computer link and choose Properties
    2. Press the Start + Break key combination (the top right key which also says Pause)
    3. Click start, choose control panel, and type system in the top right search box
  2. Click Advanced system settings in the Tasks menu down the left hand side
  3. Click the Advanced tab
  4. Click the Settings button in Startup and Recovery
  5. Use the drop down "Default operating system" to choose your OS.
  6. Click OK on all the windows until you are back to System dialog.

And that's all there is to booting up cleanly in your preferred OS.

Bonus tip

In case you didn't go ooh and aah when I mentioned the Start + Break key combo earlier then I recommend you try it now. When I sit down at a new pc to fix it for somebody its normally the first thing I use to see if the spec (processor and ram) meets the OS requirements. Its useful in more scenarios than that though such as getting networking info and getting a clickable device manager link up really fast.

Master user friendly date of birth selection with the AjaxControlToolkit Calendar extender

Posted on: Friday, 2 October 2009 21:19

The latest version of the AjaxControlTookit is out (September 2009 release) and it brings with it two new controls (Seadragon Image Viewer and AsyncFileUpload).

This release also has a heavy focus on quality with over 20 bugs fixed.

The most important one that caught my eye was the new Calendar attribute called DefaultView. This simple attribute will let you open up the calendar in a year -> month -> day order which means collecting date of birth information is now a lot more user friendly.

In previous releases you could switch to the year mode by clicking on the title bar of the calendar twice and experienced users knew this but the vast majority of the internet population didn't. For me this meant that I had to result to having "tip" messages on my forms so that I could be fairly sure that my poor users wouldn't sit there clicking backwards on the calendar for the whole day!

So bug number 9601 has been fixed and now we can do it easily. How easily? Well let me show you!

Code Sample

<asp:TextBox ID="DateOfBirth" runat="server" />
<cc1:CalendarExtender ID="DateOfBirth_CalendarExtender" runat="server" Enabled="True"
   TargetControlID="DateOfBirth" DefaultView="Years" />

As you can see the DefaultView attribute is set to years and when you click in the TextBox the Calendar pops up in year selection mode.

Downloadable Sample

An interactive downloadable sample can be downloaded here:

Further Reading