How to: Create a Web Part that Hosts an External Application
Applies to: SharePoint Foundation 2010
This topic gives an overview of how to create a Web Part that hosts a non-SharePoint application, possibly one that is located in a different domain from the Microsoft SharePoint Foundation web application on which the Web Part is used. Typically, your Web Part has editable properties, in which case you also need to create a tool part for the Web Part.
To create the Web Part
In Microsoft Visual Studio 2010, start an empty SharePoint project.
Add a Web Part to the project, and open the .cs or .vb source code file.
Add a using statement (Imports in Visual Basic) for the Microsoft.SharePoint.WebPartPages namespace.
Set your Web Part class to inherit from ClientApplicationWebPartBase, instead of the default WebPart.
Override, as needed, the class’s constructor, CreateChildControls method, and RenderContents method.
If you want to make it possible for your Web Part to be used with a custom External Application Provider (EAP), your CreateChildControls method should do the following:
Call the inherited GetExternalApplicationRequestResult() method.
Call the inherited GetInitParams() method.
Call the GetContentControl(String) method of the SPExternalApplicationRequestResult object that is returned by the call of the GetExternalApplicationRequestResult() method, and pass to it, as a parameter, the String object that is returned by the call to the GetInitParams() method.
If no custom EAP was created and registered with the web service that contains the web application, this series of calls does nothing.
If the Web Part’s External Application XML includes custom properties, you must create a custom EAP to read them. As part of the process of creating the custom EAP, you implement the OnApplicationWebPartCreateChildControls(SPExternalApplicationRequestProperties) method. For more information about creating a custom EAP, see How to: Create a Custom External Application Provider.
If your Web Part has editable properties, implement the inherited CreateEditorParts() method to create an object of your tool part class. For more information about this class, see the procedure To create the tool part.
To create the tool part
Add another Web Part to the project.
Set your class to inherit from EditorPart instead of the default WebPart.
Add an implementation of the SyncChanges() method to read editable properties from the Web Part into editable controls in the tool part.
Add an implementation of the ApplyChanges() method to read values from the controls in the tool part and assign them to the properties of the Web Part.
Override, as needed, the CreateChildControls method, RenderContents method, and other members.