Saturday 29 March 2008

Open Visual Studio Project Folder in Windows Explorer

Visual Studio 2008 has this feature already built in. If you’re still using VS2005, it’s easy to add:

Select Tools, External Tools to bring up the External Tools dialogue box. Enter a title in the title field. In the command field, enter the path to the Windows Explorer executable. In the arguments field, enter $(ProjectDir) or select Project Directory from the side menu. Your dialogue should look as follows. Click OK.



You could leave it there. You can now click on a project in Solution Explorer and select Tools, External Tools, and pick the item that you added. Windows Explorer will open at the project’s location. To make things even slicker, add the external tool as an item on the tool bar. To do this, right-click on the tool bar and select Customize. In the left-hand pane of the dialogue box, select Tools. In the right-hand pane, select the item you added and drag to the tool bar. This is tricky as the tools are just shown as External Command 1, External Command 2 and so on. You will need to work out the number assigned to yours.



Once you’ve dragged the right one to the tool bar, you can give it a name and icon as you like by right-clicking on it again (still in Customization mode) and tweaking the settings.

Wednesday 26 March 2008

Cannot set a value on node type 'Element'

This error occurs if you wrongly use the Value property of XmlNode to change the value of an element.
XmlDocument xdoc = new XmlDocument();
xdoc.Load( MapPath( "XmlSample.xml" ) );
XmlNode node =
xdoc.SelectSingleNode( "//element[@id=100]" );

// The following line will lead to
// an InvalidOperationException
node.Value = "New value!!";

xdoc.Save( MapPath( "XmlSample.xml" ) );

Instead, use the InnerText property:
node.InnerText = "New value!!";

[Edited: 4 Aug 2008]

Tuesday 25 March 2008

Validate XML in IE using JavaScript

Slightly off-topic, but as there don’t seem to be many good examples on the web of how to validate an XML document in IE using JavaScript, here’s a quick snippet. In the event of an XML error, an error message is displayed in the div.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>XML Validator</title>

<script type="text/javascript">
function loadit()
{
var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.validateOnParse = true;
xmlDoc.async="false";
xmlDoc.load("MyXmlFile.xml");

if (xmlDoc.parseError != '0')
{
document.getElementById("error").innerHTML
= xmlDoc.parseError.reason;
}

}
</script>

</head>
<body onload="loadit();">
<div id="error">
</div>
</body>
</html>

Wednesday 19 March 2008

Windows Firewall has blocked some features of a program

Should I keep blocking this program?

Unable to find script library '/aspnet_client/ system_web/1_1_4322/WebUIValidation.js'

If you get this error using .NET 1.1, try reinstalling the JavaScript file by navigating to your Framework directory (eg. C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322) and running the following command:

aspnet_regiis -c

Create a virtual directory under your web site root called ‘aspnet_client’ with all the default options and point it to the aspnet_client folder under the web root (eg. C:\Inetpub\wwwroot\aspnet_client).

Make sure you have appropriate backups before attempting these suggestions, in case you need to roll back.

Error Saving a Query String to a Cookie

Here’s one to note. I have some code that saves the requested URL to a cookie and later retrieves it. The strange thing was that when retrieving the value, anything after an ampersand in the query string was lost. The solution was to encode the Url using UrlEncode() (not HtmlEncode()).

Response.Cookies["RequestedPage"].Values.Add("Url", HttpUtility.UrlEncode(value))

Wednesday 12 March 2008

The following applications should be closed before continuing with set-up

Installing the .NET 3.5 Framework on a server this morning, I got this beauty of an error message:


Superb.

Tuesday 11 March 2008

Root element is missing

This exception arises if you store the Sitecore and Sitecore Modules folders outside of the web root and have forgotten to create virtual directories under the web root that point to them.

How many CMS developers does it take to change a light bulb?

None. It's a content issue.

(Sorry.)