Monthly Archives: January 2007

System.Web.HttpException: The file ‘/path/to/userControl.ascx’ does not exist.

If you’re working with User Controls (or other server side controls) and your file structure looks something like this:

[] = directory

[root]
     [userControls]
          ucTest.ascx
     .....
     ucContainer.aspx
     Web.config

And in your ucContainer.aspx file you have something similar to this:

< %@ Register Src="userControls/ucTest.ascx" TagName="UserControl" TagPrefix="uc1" %>
...
...
<uc1:UserControl id="ucUserControl" runat="server" />
...
...

And from your code behind, you are loading the control like this:

ucUserControl.LoadControl("userControls/ucTest.ascx");

It will compile with no problems, BUT at run time it will give you this nasty error message:

Exception Details: System.Web.HttpException: The file '/path/to/ucTest.ascx' does not exist.

This happens because when you load your control, you need to do it like this:

ucUserControl.LoadControl("~/userControls/userControl.ascx");

Also, make sure you add the tilde (~) character in your .aspx Register directive, Like so:

< %@ Register Src="~/userControls/ucTest.ascx" TagName="UserControl" TagPrefix="uc1" %>

The ~ (tilde) character is the root path reference syntax which lets you add a reference to your controls, pages, etc. without having to hard code relative paths into your URLs like so:

ucUserControl.LoadControl("../../userControls/userControl.ascx");

Using this syntax will let you move your controls to other sub directories (if you ever need to) without having to worry about going back to your ucContainer.aspx.sc file and change the ‘hard coded’ path to the UC’s new location.

Of course, if the .ascx file and its container reside in the same directory, you don’t need to include the tilde (~) character into your URL’s path.

Hope this helps :)

Just Upgraded to Version 2.1

WordPress 2.1 Ella has been released a few hours ago. I just upgraded my blog to this new version and it’s just awesome. These are some of its new features:

  • Autosave makes sure you never lose a post again.
  • Our new tabbed editor allows you to switch between WYSIWYG and code editing instantly while writing a post.
  • The lossless XML import and export makes it easy for you to move your content between WordPress blogs.
  • Our completely redone visual editor also now includes spell checking.

You can read more on their release page.

The guys at WordPress.org rock!