WebPart.EnsureInterfaces 方法

请注意:此 API 现在已过时。

提供可连接 Web 部件的通知应确保所有使用RegisterInterface方法注册它的接口。

命名空间:  Microsoft.SharePoint.WebPartPages
程序集:  Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)

语法

声明
<ObsoleteAttribute("Use ConnectionProvider or ConnectionConsumer attribute to create ConnectionPoint instead.")> _
Public Overridable Sub EnsureInterfaces
用法
Dim instance As WebPart

instance.EnsureInterfaces()
[ObsoleteAttribute("Use ConnectionProvider or ConnectionConsumer attribute to create ConnectionPoint instead.")]
public virtual void EnsureInterfaces()

备注

开发可连接的 Web 部件时必须重写EnsureInterfaces方法。开发 Web 部件不支持连接时,重写此方法不需要。

示例

下面的代码示例演示重写的EnsureInterfaces方法。此代码示例是示例的一个更大提供的ICellProvider接口的一部分。

创建可连接的 Web 部件的各个步骤的概述,请参阅Creating a Connectable Web Part。

// Step #4: Override the EnsureInterfaces() method and call the RegisterInterface method.
public override void EnsureInterfaces()
{
    // If your Web Part is installed in the bin directory and the Code Access Security (CAS) setting doesn't 
    // allow Web Part Connections, an exception will be thrown. To allow your Web Part to behave 
    // well and continue working, a try/catch block should be used when attempting to register interfaces.
    // Web Part Connections will only work if the level attribute of the <trust> tag in the 
    // web.config file is set to WSS_Minimal, WSS_Medium, or Full. By default a new SharePoint site
    // is installed with the trust level set to WSS_Minimal.
    try
    {
        // Register the ICellProvider Interface
        // <param name="interfaceName">Friendly name of the interface that is being implemented.
        // It must be unique on the client so the _WPQ_ token is used.</param>
        // <param name="interfaceType">Specifies which interface is being implemented.</param>
        // <param name="maxConnections">Defines how many times this interface can be connected.</param>
        // <param name="runAtOptions">Determines where the interface can run.</param>
        // <param name="interfaceObject">Reference to the object that is implementing this interface.</param>
        // <param name="interfaceClientReference">Name used to reference the interface on the client. 
        // It must be unique on the client so the _WPQ_ token is used.</param>
        // <param name="menuLabel">Label for the interface which appears in the UI</param>
        // <param name="description">Description of the interface which appears in the UI</param>
        // <param name="allowCrossPageConnection">Specifies if the interface can connect to a Web Part
        // on a different page. This is an optional parameter with a default of false. Note that only some 
        // server side interfaces are allowed to connect across pages by the Web Part infrastructure. 
        // The ICellProvider interface is not allowed to connect across pages.</param>
        RegisterInterface("MyCellProviderInterface_WPQ_",            //InterfaceName    
            InterfaceTypes.ICellProvider,                            //InterfaceType
            WebPart.UnlimitedConnections,                            //MaxConnections
            ConnectionRunAt.Server,                                  //RunAtOptions
            this,                                                    //InterfaceObject
            "CellProviderInterface_WPQ_",                            //InterfaceClientReference
            "Provide Cell To",                                       //MenuLabel
            "Provides a single value to a cell consumer Web Part."); //Description
    }
    catch(SecurityException se)
    {
        _registrationErrorOccurred = true;
    }
}
' Step #4: Override the EnsureInterfaces() method and call the RegisterInterface method.
Public Overrides Sub EnsureInterfaces()
    ' If your Web Part is installed in the bin directory and the Code Access Security (CAS) setting doesn't 
    ' allow Web Part Connections, an exception will be thrown. To allow your Web Part to behave 
    ' well and continue working, a try/catch block should be used when attempting to register interfaces.
    ' Web Part Connections will only work if the level attribute of the <trust> tag in the 
    ' web.config file is set to WSS_Minimal, WSS_Medium, or Full. By default a new SharePoint site
    ' is installed with the trust level set to WSS_Minimal.
    Try
        ' Register the ICellProvider Interface
        ' <param name="interfaceName">Friendly name of the interface that is being implemented.
        ' It must be unique on the client so the _WPQ_ token is used.</param>
        ' <param name="interfaceType">Specifies which interface is being implemented.</param>
        ' <param name="maxConnections">Defines how many times this interface can be connected.</param>
        ' <param name="runAtOptions">Determines where the interface can run.</param>
        ' <param name="interfaceObject">Reference to the object that is implementing this interface.</param>
        ' <param name="interfaceClientReference">Name used to reference the interface on the client. 
        ' It must be unique on the client so the _WPQ_ token is used.</param>
        ' <param name="menuLabel">Label for the interface which appears in the UI</param>
        ' <param name="description">Description of the interface which appears in the UI</param>
        ' <param name="allowCrossPageConnection">Specifies if the interface can connect to a Web Part
        ' on a different page. This is an optional parameter with a default of false. Note that only some 
        ' server side interfaces are allowed to connect across pages by the Web Part infrastructure. 
        ' The ICellProvider interface is not allowed to connect across pages.</param>
        RegisterInterface("MyCellProviderInterface_WPQ_", InterfaceTypes.ICellProvider, WebPart.UnlimitedConnections, ConnectionRunAt.Server, Me, "CellProviderInterface_WPQ_", "Provide Cell To", "Provides a single value to a cell consumer Web Part.") 'Description - MenuLabel - InterfaceClientReference - InterfaceObject - RunAtOptions - MaxConnections - InterfaceType - InterfaceName
    Catch se As SecurityException
        _registrationErrorOccurred = True
    End Try
End Sub

另请参阅

引用

WebPart 类

WebPart 成员

Microsoft.SharePoint.WebPartPages 命名空间