Welcome Guest! Register/Login
Web services for automated content conversion and deployment

Building Web Applications with Hyper.Net Framework SDK

Show Comments (0)    Public Domain Bookmark this publication
Building Web Applications with the Hyper.Net Framework SDK The Hyper.Net Framework SDK in Detail How to Build a Basic Hyper.Net Web Application Using the Hyper.Net Framework SDK Creating an Application Using C# Creating the Acme ASP.Net Pages
Creating the Acme ASP.Net Pages
Let us complete the pages we started to create in earlier sections. In Visual Studio .Net go to the “Project” menu and select “Add Web Form…” Name this form blob.axd.
In the design view from the toolbar select the tab “Hyper.Net Framework SDK” we created earlier, and drag the “Content” web server control and drop it into the workspace, make sure everything looks like in Figure 6.
Figure 6 – blob.axd
This page has no code behind, and that’s all we will do to this page. The beauty of this Hyper.Net Web Server Control (and the others), is that it encapsulates all the logic needed to get the proper content displayed in the browser without having to write a line of code.
Let’s now create the link.axd page (it handles dynamic resolution of hyperlinks). Here we’ll see the BOM classes in action for the first time, and see how easy it is to use them to perform any kind of content operation in an object oriented way.
In Visual Studio .Net go to the “Project” menu and select “Add Web Form…” Name this form link.axd, and in the workspace select the “HTML” view and add the following HTML code:
<span id="span_result" runat="server" style="FONT-SIZE: 8pt; FONT-FAMILY: Verdana, Tahoma, Arial"></span>
Keep in mind the name of the span tag id, and remember that it’s set to run at the server side. Later you’ll learn why we have created this code. Now press F7 to switch to the code behind view to start to use the BOM.
The code you are about to write it is one of the most complex you will see in the HNAcme application, and requires that you have a solid knowledge of how to program with ASP.NET. However if you’re a moderately-experienced developer, you’ll recognize that this piece of code is actually quite easy. It’s a really good sign when the most complex code is actually the easy stuff.
Make sure your code looks like the shown in the Code-Snippet 4. Just below we’ll go deeply into the code details and explain what’s happening.
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
// Program specifics
using System.Xml;
// Hyper.Net SDK
using Hyper.Net.Framework.BOM;
using Hyper.Net.Framework.Common;
 
namespace HNAcme
{
 public class link : System.Web.UI.Page
 {
   protected System.Web.UI.HtmlControls.HtmlGenericControl span_result;
 
   private void Page_Load(object sender, System.EventArgs e)
   {
     System.Configuration.AppSettingsReader configurationAppSettings =
             new System.Configuration.AppSettingsReader();
     string _topicaspx =
               ((string)(configurationAppSettings.GetValue("ContentDisplayURL",
               typeof(string))));
 
     string DOC_UNID = Request.QueryString["DOC_UNID"];
     if(DOC_UNID != string.Empty && DOC_UNID != null)    
   Response.Redirect(string.Format("{0}?DOC_UNID={1}", _topicaspx, DOC_UNID));
     else
     {
 string DB = Request.QueryString["DB"];
 if (DB !="" && DB != null) DB = DB.Replace( "'", "''" );
       string PT = Request.QueryString["PT"];
  if (PT !="" && PT != null) PT = PT.Replace( "'", "''" );
  string DH = Request.QueryString["DH"];
  if (DH !=""&& DH != null) DH = DH.Replace( "'", "''" );
  if((DH != string.Empty && DH != null) || (PT != string.Empty && PT != null))
   {
     Search _srch = new Search("topic.aspx","Content","NSM",-1);
     _srch.SearchCriteria = publication.IsEffective == 1 &
     publication.Audience == "Production";
    
     if(DH != string.Empty)
            _srch.SearchCriteria = _srch.SearchCriteria & topic.Heading == DH;
     if(PT != string.Empty)
            _srch.SearchCriteria = _srch.SearchCriteria & publication.Title == PT;
 
     Hyper.NetField[] _hnfa = new Hyper.NetField[4];
     _hnfa[0] = topic.TopicID;
     _hnfa[1] = topic.Heading;
     _hnfa[2] = publication.Title;
     _hnfa[3] = publication.Category;
 
     _srch.AddNewOutputNode("Topic",_hnfa,"{0} {1} {2} {3}");
     XmlDocument _res = _srch.Execute();
     if(_res.DocumentElement.ChildNodes.Count > 0)
      {
  XmlNodeList _xndl = _res.SelectNodes("//Topic");
  if(_xndl.Count == 1)
       Page.Response.Redirect(string.Format("{0}?DOC_UNID={1}", _topicaspx, _xndl[0].Attributes["topic_TopicID"].Value));
  else
  {
    span_result.InnerHtml = string.Format("<b>{0}</b> documents matching the criteria were  found.<br><br>",_xndl.Count);
    HtmlTable _tbl = new HtmlTable();
    _tbl.CellSpacing = 5;
    _tbl.CellPadding = 2;
    _tbl.Width = "100%";
    _tbl.Attributes["style"] = "FONT-SIZE: 8pt; FONT-FAMILY: Verdana";
    HtmlTableRow _tblrH = new HtmlTableRow();
    HtmlTableCell _tblcH1 = new HtmlTableCell();
              _tblcH1.BgColor = "#dcdcdc";
   HtmlTableCell _tblcH2 = new HtmlTableCell();
             _tblcH2.BgColor = "#dcdcdc";
             _tblcH1.InnerHtml = "<b>Document Heading</b>"; _tblcH2.InnerHtml =  <b>Publication Category</b>";
    _tblrH.Cells.Add(_tblcH1);
    _tblrH.Cells.Add(_tblcH2);
    _tbl.Rows.Add(_tblrH);
    foreach(XmlNode _xnd in _xndl)
    {
         if(_xnd.Attributes["topic_TopicID"] != null)
      {
   HtmlTableRow _tblr = new HtmlTableRow();
   HtmlTableCell _tblc1 = new HtmlTableCell();
   HtmlTableCell _tblc2 = new HtmlTableCell();        
   _tblc1.InnerHtml =
      string.Format("<a href=\"{0}?DOC_UNID={1}\" target=\"Content\">{2}</a>",
  _topicaspx,          
              _xnd.Attributes["topic_TopicID"].Value,       
              _xnd.Attributes["topic_Heading"].Value);
         if(_xnd.Attributes["publication_Category"] != null)
    _tblc2.InnerHtml = string.Format("{0}\\{1}",       _xnd.Attributes["publication_Category"].Value,     _xnd.Attributes["publication_Title"].Value);    _tblr.Cells.Add(_tblc1);
 _tblr.Cells.Add(_tblc2);     _tbl.Rows.Add(_tblr);
    }
   }
   span_result.Controls.Add(_tbl);
 }
}
 else
  span_result.InnerHtml = "<font color=\"blue\">No documents for the current link were found.<br>Process Terminated.</font>";
}
else
  span_result.InnerHtml = "<font color=\"red\">No parameters found.<br>Process Terminated.</font>";
}
}
 
 override protected void OnInit(EventArgs e)
 {
   InitializeComponent();
   base.OnInit(e);
 }
 private void InitializeComponent()
 {    
   this.Load += new System.EventHandler(this.Page_Load);
 }
}
}
Code-Snippet 4 – link.axd code behind
Loading, please wait...
About Publications
Contributor
Aruna
Published: 5/19/2010
Tags:
0 128 0
Display Options
Embed, Share & Subscribe
Download
Rate & Report
Statistics