Reader Level:
Articles

Using a Windows Application on the Web

By Prabakar Samiyappan on May 30, 2006
In this article, author shows how to create a Windows Forms application and use it in an ASP.NET application for the Web.
  • 0
  • 0
  • 43623

Introduction

In this article, I will show how to use a Windows Forms application in an ASP.NET Application targets for the Web.

Note: Try to use the Microsoft windows control, avoid third party control. Because we are going to use the same control on web.

Advantages:

  • Reduces the coding time and resource needed for web.
  • Bring the desktop to your web

Requirement:

Develop a windows application. For developing weather you can use windows controls are third party control that's not a matter.

Process:

1. Open  "New Project ", select Visual C# Project and select Windows Application and name the project as  'WindowsTOWeb' and click Open. See Figure 1.

figure1.gif

Figure 1.

2. Place some controls on the Forms such as Labels, TextBoxes, and buttons. See Figure 2. I add three labels, three TextBoxes, and two button controls and change their properties accordingly.

figure2.gif

Figure 2.

3. When you run the application, the form will look like Figure 3.

figure3.gif

Figure 3.

4. Now we want to convert the windows application in to a usercontrol so then we can use the user control in our Web application. To convert the windows application in to a user control, we need to follow the following steps two steps:

  • Convert the

    public class Form1 : System.Windows.Forms.Form

                            TO

    public class Form1 : System.Windows.Forms.UserControl
    (See Figure 4)

    figure4.gif
    Figure 4.

  • Comment the    

    this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); of the windows.

Now your windows form application is converted to a user control

5. Now click the property of the project and change the "Output Type" from Windows Application to Class Library (See Figure 5)

figure5.gif

Figure 5.
 
6. Before compiling the project comments the "thread". See Figure 6.

figure6.gif

Figure 6.

Now You have successfully created a user control that contains the functionality of our Windows Forms applicatin.

7. Now we are going to add a Web Application to the solution by adding a new ASP.NET Web Application project. I call project WinToWeb. See Figure 7.
figure7.gif

Figure 7.
 
8. Now create a strong name for your user control by using "sn.exe ", which is in the location

'C:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\Bin'.

The syntax for creating the string name is

C:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\Bin\sn -k "C:\Strongname.snk"

now the strong name has been created and it is in the c: in the name of strongname.snk

9. After creating the strong name specify the path of the strong name in "Assemblyinfo.cs " file in the [assembly: AssemblyKeyFile("c:\strongname.snk")] attribute

Now the first way of using the user control in a Web application.

10. Now by using the "regasm.exe" create and place the CLSID of your dll in the registry the exe file which is in the location "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\ ".

11. Then by using the Gacutil.exe register your WindowsToWeb .dll the the registry. Then go to the registry and search by the name "WindowsToWeb.dll" and copy the CLSID to the code behind as Specified in the figure. See Figure 8.

figure8.gif

Figure 8.

12. Now you can see the windows control in the web form. See Figure 9.

figure9.gif

Figure 9.

13. Run your web application. Congratulations. Your Windows Forms functionality is available on the Web now. See Figure 10.

figure10.gif

Figure 10.

Conclusion:

This is a sample application, which I have created when I am in position to run the windows application on the Web. By using this you can run only the simple applications.

Prabakar Samiyappan

MCP Certified.Working in Microsoft Technology for the Past 4 Years. http:\\sharpurdotnet.blogspot.com

COMMENT USING

Trending up