Export (0) Print
Expand All

How to: Create a Web Part that Hosts an External Application

SharePoint 2010

Last modified: September 01, 2011

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

  1. In Microsoft Visual Studio 2010, start an empty SharePoint project.

  2. Add a Web Part to the project, and open the .cs or .vb source code file.

  3. Add a using statement (Imports in Visual Basic) for the Microsoft.SharePoint.WebPartPages namespace.

  4. Set your Web Part class to inherit from ClientApplicationWebPartBase, instead of the default WebPart.

  5. 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:

    1. Call the inherited GetExternalApplicationRequestResult() method.

    2. Call the inherited GetInitParams() method.

    3. 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.

  6. 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.

  7. 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

  1. Add another Web Part to the project.

  2. Set your class to inherit from EditorPart instead of the default WebPart.

  3. Add an implementation of the SyncChanges() method to read editable properties from the Web Part into editable controls in the tool part.

  4. 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.

  5. Override, as needed, the CreateChildControls method, RenderContents method, and other members.

Show:
© 2014 Microsoft