HtmlBox CodeSample - URL as file within application

From Visual WebGui Wiki

Jump to: navigation, search


Overview

When assigning to the URL property a file within the virtual folder of the application, the path must be slightly different depending on if the file is on the root folder, or on a subfolder. This codesample gives you idea on how to make that irrelevant.

Note that it may also be useful to use HttpRuntime.AppDomainAppVirtualPath for an absolute path to your application, not including the protocol, just the absolute path, see here.

VB.NET code

If Context.HttpContext.Request.ApplicationPath.EndsWith("/") Then
    htmlBox1.Url = Context.HttpContext.Request.ApplicationPath & "HTMLPage1.htm"
Else
    htmlBox1.Url = Context.HttpContext.Request.ApplicationPath & "/HTMLPage1.htm"
End If

C# Code

if (Context.HttpContext.Request.ApplicationPath.EndsWith("/") )
{
    htmlBox1.Url = Context.HttpContext.Request.ApplicationPath + "HTMLPage1.htm";
} else {
    htmlBox1.Url = Context.HttpContext.Request.ApplicationPath + "/HTMLPage1.htm";
}
Personal tools