Accessing network file shares from a command prompt

If you’ve ever tried to access a network file share in a command prompt by simply using the cd command, you’ll know that it just complains that “CMD does not support UNC paths as current directories”. Well, there is a way to do it (two in fact):

net use z: \\machine\share
pushd \\machine\share

Both of these approaches map the network share to a local drive letter that you can change to using the cd command.

The first one can be combined with the /user switch to provide additional user details:

net use z: \\machine\share /user:domain\username

The bonus of using the pushd command over the net use command is that it will automatically change the current directory to the mapped drive (which will be the first unused drive letter available in reverse alphabetical order). Also, when finished with the network share, you can use the popd command to remove the mapped drive.

Google page rank and redirection

After reading Jeff Atwood’s recent post about URL rewriting to prevent duplicate URLs, I started to look at my own site’s redirections, specifically with regards to Google’s page rank. The first thing I noticed was that I had two different page ranks for this site. had a page rank of 3, whilst had a page rank of zero, even though I’ve never really used the version of the url.

Jeff’s ISAPI rewrite rules were helpful, but were not going to work on an Apache server. The Apache docs for the URL rewriting engine were very detailed, but a little too verbose to glean which exact rules I needed. Luckily, the Search Engine Promotion Help site has an example of exactly what I was after.

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.adrianbanks\.co\.uk [NC]
RewriteCond %{HTTP_HOST} !^report\.adrianbanks\.co\.uk [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^(.*)$1 [L,R=301]

The only alteration I had to make was to add in an extra line to stop any subdomains of my site being redirected to the main site.

Now for a quick explanation of how the rules work:

  • The RewriteRule will only run if all of the preceding rewrite conditions (RewriteCond) are true.
  • Line 1 turns on the rewrite engine in Apache.
  • Line 2 will be true if the host url is not
  • Line 3 will be true if the host url is not (this is my alteration for my subdomain).
  • Line 4 will be true if the host url is not empty.

Only if all of these conditions are met will the rule run.

Having made this change, the page rank for has now jumped to up 3.

Ambiguous match found

Whilst porting an ASP.Net application to the .Net 2.0 framework, I came across a spurious error when viewing a few specific pages. The error was occurring during the runtime compilation of these specific aspx pages.

Parser Error

Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

Parser Error Message: Ambiguous match found.

To make this error more confusing, the error was reported on line 1 of the aspx page which contained nothing more than the page directive tag.

After a bit of searching, I found the cause of the problem. The cause was that there were two member variables declared with names that differed only by case (one was an ASP.Net PlaceHolder control, the other an int). Simply renaming one of the variables solved the compilation error.

Eran Sandler has also encountered this problem, but delves a lot deeper into what is going on.

Selecting 'No to all' in a confirm file replace dialog box

When copying files in Windows, you are sometimes prompted about replacing an existing file.

Confirm file replace

The available options are Yes, Yes To All, No and Cancel. But what if you are copying a large number of files and want to choose the non-existent ‘No To All’ option? Well simply hold in the shift key while clicking the No option and it will apply that choice to all subsequent dialogs within the current operation.

Testing applications in different cultures

Having worked on an application that required localising so that it can be translated into different languages, I know how hard it can be to test the different possibilities while still developing the code. This is especially so if the language is automatically detected from the current culture of the operating system.

Shawn Farkas came up with a simple solution for quickly testing code under different cultures that involves creating a bootstrap application to first set the required culture on the current thread and then launch the application to be tested.

One downside is that only the culture of the main thread is set, but for simple GUI testing this should be adequate in most cases.

Running applications on different versions of the .Net framework

Peter Laudati posted about migrating applications from .Net 1.1 to .Net 2.0. In doing so, he listed the different behaviours of .Net applications when running on computers with different versions of the .Net Framework installed:

Application type Computer with 1.1 Computer with 2.0 Computer with 1.1 and 2.0
1.1 stand-alone application (Web or Microsoft Windows client) Loads with 1.1 Loads with 2.0 Loads with 1.1
2.0 stand-alone application (Web or Microsoft Windows client) Fails Loads with 2.0 Loads with 2.0
1.1 add-in to a native application (such as Office or Internet Explorer) Loads with 1.1 Loads with 2.0 Loads with 2.0 unless the process is configured to run against 1.1
2.0 add-in to a native application (such as Office or Internet Explorer) Fails Loads with 2.0 Loads with 2.0

Managed stack explorer

A neat little project on CodePlex called Managed Stack Explorer enables you to monitor running .Net applications.

Using this tool, you can view all currently running managed applications, monitor all of their threads, and even collect stack traces at regular intervals. Very useful for getting information about applications whilst running outside of a debugger.

Suppressing FxCop message

Using the latest version (1.35) of FxCop, it is possible to exclude generated warning messages in the source code instead of having to exclude them in the FxCop project file. This is accomplished using the System.Diagnostics.CodeAnalysis.SuppressMessageAttribute class.

To exclude a message, simply mark up the method with the SuppressMessage attribute, declaring both the rule category and the specific rule to exclude:

[SuppressMessage("Microsoft.Design", "CA1062:ValidateArgumentsOfPublicMethods")]
public string ConvertToString(object obj)
    return obj.ToString();

The above example will exclude the “Validate Arguments Of Public Methods” rule from the Design category for the ConvertToString method (although in this contrived example it is probably a bad idea to do so as passing in a null will clearly cause problems).

One extra “tweak” that can be utilised in this scenario is the Justification property. Altering the above code to:

[SuppressMessage("Microsoft.Design", "CA1062:ValidateArgumentsOfPublicMethods", Justification="I do have a valid reason")]
public string ConvertToString(object obj)
    return obj.ToString();

will allow the person excluding a message to provide a reason for doing so in the code, alongside the exclusion. FxCop (v1.35) currently doesn’t display this in its output, but will do in the next release (source). It does however output the justification to a generated report if the options are set to output exclusions to the report.

Excluding FxCop messages in the source code has advantages over excluding them in the FxCop project as it demonstrates that the message has been specifically excluded for that particular case, but also will withstand class and namespace changes. It also makes switching from the standalone FxCop to Visual Studio’s code analysis an easier process.

In order to allow the SuppressMessage attribute to work, a CODE_ANALYSIS conditional compilation symbol must be defined for the project. Without this, FxCop will ignore the suppressed attribute and will still generate a warning.

More details can be found on the FxCop blog.

ASP.Net web development helper For IE

Nikhil Kothari has made a nice little Web Development Helper for ASP.Net. It works as a plugin for Internet Explorer and is similar to the Internet Explorer Development Toolbar, but with more of an ASP.Net twist.

Some of its most useful features are:

-Rich error information for script errors, including call stack, script url and line number.

  • a DOM inspector with filtering to enable easy viewing of particular items.
  • a view state browser.
  • trace information can be shown in a separate dialog instead of in the page itself.
  • a full HTTP/HTTPS logger showing all traffic between the browser and the server.

The Web Development Helper requires .Net 2.0 to run and can only work on the same machine as the server, but this should not be a problem during development.

After installation, I had the same problem that lots of other people seem to have in that clicking the newly installed toolbar button did nothing. The suggested fix of installing the Internet Explorer Development Toolbar solved the problem though. Nikhil also suggested that a reboot (or killing explorer.exe) may also work because information about plugins is cached on startup.