Loading class by name from another asp.net application

What if you need to load a class, a webcontrol or a user control that is not in the current web application and the .dll of the other application is not used in the current application?

Remoting can help to do that. The control to load will be created with remoting using the class name given as string.

'Vb example, loading a web control from another application

Dim dllPhysicalPath as String = "C:\...\...\myOtherApplication.dll"
Dim ClassName as String = "MyNamespace.MyClassName"
Dim controlHandle As Runtime.Remoting.ObjectHandle
controlHandle = Activator.CreateInstanceFrom(dllPath , ClassName )
' converting to webcontrol
dim myCtr as WebControl = CType(controlHandle .Unwrap, WebControl)
Page.Controls.Add(myCtr )

No comments: