Wednesday, August 13, 2008

ASP.Net, Tilde(~), Virtual Paths and the Image Control

When using master pages and content pages located in different sub directory levels, you usually use a url with a root indicator (~). Sometimes the designer is unable to resolve or display images located off of the application root, even when the url containes a tilde (~) at the beginning of the path.

< img src="~/Image/picture.jpg" />

The tilde (~) is a shortcut to the HttpRuntime.AppDomainAppVirtualPath which will normally resolve back to the root of the virtual directory but this shortcut will only be resolved within server side controls. The standard HTML image control (img) is not rendered at the server and will simply pass the tilde on to the client browser. The issue was related to this and not directly to the use of master pages.
The solution is to insure that the control is rendered at the server. This can be done by adding the runat="server" property to the standard HTML image control or by using the ASP.NET image control.

< img src="~/Image/picture.jpg" runat="server" />
< asp:image runat="server" imageurl="~/Image/picture.jpg" />

Friday, January 04, 2008

VS2003: "unable to read the project file" "the system cannot find the file specified"

The web project would not be loaded, only be displayed as "unavailable".

Solution:
  • Exit VS
  • Delete the .SUO file
  • Start VS
  • Set the source control that you lost