Is it possible to convert a WinForm to a WebForm in .NET?
It's not something you can do automatically.
The trick is both Winforms and Webforms represent a form using a plain old class. However, instances of the class in Webforms are short-lived compared to Winforms; each Webforms class instance represents only one HTTP request, rather than the entire lifetime of the form, as with Winforms. Every time you handle an event for your form in ASP.Net Webforms you're working with a brand new instance of the class. Microsoft went to a lot of trouble to try cover for this issue as much as possible, but in the end it's just not a good idea to think of a Webform in the same terms as a Winform.
You can definitely take a Winforms app and rewrite it to use Webforms, but it will be just that: a rewrite.
Yes, it is possible. If you have designed the application well enough it should be relatively easy to convert a Win Forms application to a web forms application by just swapping out the UI layer and replacing it. You are re-using the logic and data layers (which is where all the functionality would be).
Obviously, you have to write a new UI layer from scratch, but, if the logic layer is written well enough that isn't going to be too much work compared with writing the whole application again from scratch.
However, there are some gotchas even if you have a very well written application. The logic layer may assume a stateful application in which case it may rely on lazy loading. In a web application you have a stateless model which is run on requests and responses. In that scenario you'd know exactly what you need up front and can load just the bits you need and not other things that may be needed later on... because later on will be a different request/response cycle and all the data you collect now is going to be dropped as soon as the current response is completed.
I've recently been putting the logic of an application that was originally a WinForms into MVC and the biggest barrier to getting a responsive speed is the fact that, although reasonably well written, the logic layer assumed a stateful environment. The same application is being also re-written for WPF (another stateful environment) without so many issues.
Converting a desktop application to a web application has several challenges:
- Access to hardware
- Windows API calls
- Management of the application state
- Access to the file system
- Access control
- Use of desktop-specific UI/UX/controls
There are options to convert desktop applications in an automated way, these can convert both the UI and the code of the application:
- http://www.codeproject.com/Articles/9307/Converting-WinForms-Web-Forms-using-CodeDom
- http://www.mobilize.net/webmap
- http://visualwebgui.com/ (apparently no longer exists)
Even when using automated migration tools, in most of the cases you will have to perform a significant amount of manual work to get the application working in the same way as the original one.
Some of these tools will help with different objectives, the first one will help you convert only the UI and to WebForms, the last two ones will generate ASP.NET MVC, one using a custom runtime and set of libraries and the other with common HTML/JS/CSS libraries such as Kendo MVVM, Kendo UI, AngularJS or Bootstrap among others. These tools will provide a solution that will be faster than writing the application in the web from scratch and will provide solutions or at least guidelines to approach the challenges mentioned before. However, there will be some differences from an application that was designed for the Web, simply because the architectures are different and usually the way of writing the code for a desktop application assumes thing that cannot be assumed for a web one.
Disclaimer: I work for Mobilize.Net, who built WebMAP.