Developing your first Visual WebGui gateway

Page 1 of 2
  1. Introduction and Setting Up
  2. Finishing Up and Conclusion

Introduction and Setting Up

Introduction

Visual WebGui basically leverages the WinForms object model giving the developer a new development experience developing rich internet applications like outlook web access. This object model by say covers 90% of what you need in order to create an outlook web access application. So how do we bridge the WinForms object model and web development? Through the concept of Gateways.

 

 

Background

Every WebGui component can declare it self as a WebGui gateway using the IGatewayControl interface, this allow controls to declare virtual URLs that are handles by the control by declaring actions. The IGatewayControl contains a method that gets an action name and should return a gateway handler. The gateway handler processes the request in the exact same way as an HTTP handler does, which actually means that you can also use HTTP handlers. This means that you can actually provide embedded ASPX pages that are hosted by the WinForms object model and can interact with that model making the interoperability between WebGui and legacy applications easy.

Other places you can use gateways:

  • Providing HTML based content to IFRAMES.
  • Providing a printable version of the current view.
  • Interacting with applets, flash, activeX and so on.
  • Using ASP.NET ready controls such as Janus grid.
  • Downloading files.

Visual WebGui is completely free to use and deploy for non-commercial purposes and is also available as an open source project in SourceForge.net. The Visual WebGui site has multiple free licenses that you can apply to in order to use it freely in your production site

This article creates a file list that can be previewed by selecting the file.

Sample Image - visualwebgui_gateway1.gif 

Using the code

In order to start developing Visual WebGui you need to download the SDK from the Visual WebGui download page. The installation will install a couple of assemblies to you GAC adding the Visual WebGui capabilities to your development enviroment. Installing the Visual WebGui SDK will add a two new projects to your Visual Studio (WebGui Application and WebGui Control Library). The WebGui Application project will create you a ASP.NET new project that one class named Form1.cs instead of the WebForm1.aspx file usualy created by the ASP.NET project template. Inheriting from the Gizmox.WebGUI.Forms.Form class the Form1.cs automaticly causes this file to have a WinForms like design time behavior. When you enter the design surface of the Form1.cs class you will have an aditional WebGUI toolbox available in the toolbox pane. These components can be draged to the design surface and be used exactly as WinForms components are used on a WinForms design surface. In the properties pane of any givven component you can change the component attributes including layout properties such as Dock and Anchoring which are WinForms way of layouting components and are fully supported by Visual WebGui.

Before you can run your application you need to have your form registerd in Visual WebGui web.config configuration section to a virtual page and have Visual Studio start page set to this virtual page. Visual WebGui uses a ".wgx" IIS script map extension that needs to be added to the IIS with the same definitions as the ".aspx" script map extension but without the check file exist check box as Visual WebGui uses virtual pages mapped to Gizmox.WebGUI.Forms.Form inherited classed. After setting these configurations you can start debugging your application exactly as you debug a WinForms application.

Step 1 - Creating a new WebGui Application project

Open the new project dialog and select the WebGui Application project. In the project name textbox enter WebGUIGateway and press OK.Visual WebGui will create you a new WebGui Application project that is both ASP.NET and WinFroms, as the structure is that of ASP.NET and the form classes behave like a WinForm form forms. Double clicking the Visual WebGui form1.cs page will open the design surface that is exactly the same as the WinForm design surface. The Visual Studio tool box has an added pane named WebGUI and you can find there Visual WebGui components which are identical to WinForms components. You can drag and drop components on the design surface exactly as you do in a WinForms application and the Visual WebGui designer will generate the code with in the InitializeComponent method.

Step 2 - Creating the main form

From the WebGUI toolbox pane drag a listview component on to the design surface and in the properties pane make it docked to the top. Drag a splitter and dock it to the top as well. Docking the splitter to the top will cause it to change the list view height. Drag an htmlbox and change it's docking to fill. Add the list view two columns for the file name and the file extension. Now you have the UI part of this tutorial ready.

Step 3 - Populating the list view

Go to the form properties and change to event view. Double click the Load event handler and the designer will create you an empty event handler. Add the code bellow to handler that will populate the listview with file list from a given path. Update the path to a valid path with gif images on your computer. Notice that the code generates list items and in the Tag property sets the full path of the file.

private void Form1_Load(object sender, System.EventArgs e)
{
    DirectoryInfo objDir = new DirectoryInfo(@"C:\Inetpub\wwwroot\images");    
    foreach(FileInfo objFile in objDir.GetFiles("*.gif"))
    {
        ListViewItem item = listView1.Items.Add(objFile.Name);
        item.SubItems.Add(objFile.Extension);
        item.Tag = objFile.FullName;
    }
}

You might also like...

Comments

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Debugging is anticipated with distaste, performed with reluctance, and bragged about forever.” - Dan Kaminsky