65.9K
CodeProject is changing. Read more.
Home

Dynamic Help-System for Web Based Applications

starIconstarIconstarIcon
emptyStarIcon
starIcon
emptyStarIcon

3.60/5 (4 votes)

May 13, 2010

CPOL

1 min read

viewsIcon

23561

downloadIcon

147

Extremely simple but dynamic XML-based help system for Web based applications

helpsystem1_small.JPG

Introduction

This is a simple and quick help system which pops up page-specific help page on the base of URL. One can change the HTML text of the help anytime for any page by changing the XML file kept at the website folder.

Background

Recently I was asked by a client to develop a simple and quick help system which should be page specific and using which he can change the HTML text of the help anytime for any page by changing any static file kept at the website folder.

Using the Code

The default page is the dummy place from where hyperlink can be clicked to pop up the help for default page. This can be placed at some common place like master page which will bring the page id from XML on the basis of the URL on the address bar and then redirect to DynamicHelp.aspx - the page which is the common page for rendering help for any page.

lnkGetHelp.OnClientClick = "javascript:window.open('DynamicHelp.aspx?" + 
	GetPageQueryStringsFromXML() + "','DynamicHelp','width=500,height=300,
	toolbar=no,scrollbars=yes,resizable=no,dependent=yes');return false;";

This is the page XML I am using for mapping pageid, url and title, please note html being in CDATA, I can put any html there:

<Page id="2" url="/Default.aspx" helptitle="Default help title">
<PageHelpText>
<![CDATA[
<b>This is help manual for default page</b>
]]>
</PageHelpText>
</Page>

Then in the Help page, I am fetching the helptext on and title text on the basis of page id and rendering it on HTML page as follows:

XPathDocument doc = null;
XPathNavigator nav = null;
XPathExpression expr = null;
XPathNodeIterator iterator = null;
StringBuilder sbHtml = new StringBuilder();
//set the title bar if pagetitle value is other than 0
ttlHelp.Text = (pageTitle != "0") ? pageTitle : "";
try
{
//creates an instance of XPathDocument class and loads XML
if (System.IO.File.Exists(Server.MapPath("/Components/PageHelp.xml")))
{
doc = new XPathDocument(Server.MapPath("/Components/PageHelp.xml"));
//An XPathNavigator object acts like a cursor, 
//addressing a node in the XML document at a time
nav = doc.CreateNavigator();
// Compile a standard XPath expression
expr = nav.Compile("/Pages/Page[@id=" + pageID + "]/PageHelpText");
iterator = nav.Select(expr);
//if node is found, count would be greater than 0 
if (iterator.Count > 0)
{
//Iterate through the selected nodes
while (iterator.MoveNext())
{
//if attribute is not there but node is there, null will be returned
if (iterator.Current.InnerXml != null)
{
sbHtml.Append("Help:" + pageTitle + "<br/><br/>");
sbHtml.Append(HttpUtility.HtmlDecode(iterator.Current.InnerXml));
divHelpParent.InnerHtml = sbHtml.ToString();
}
}
}
else
{
Response.Write("Sorry! No help available for this page!");
}
}
}
finally
{
//when control is returned out of the method, corresponding ref variables are made null
sbHtml = null;
pageID = null;
pageTitle = null;
doc = null;
nav = null;
expr = null;
iterator = null;
}

Points of Interest

I liked the efficient way of bringing text from XML using XPathDocument and the dynamic nature of this tool to add any kind of help text you want into the XML itself.

History

This is the first version, I am sure you guys can give many tips for improvement, waiting for those. Thanks!