自定义转换器配置设置页

上次修改时间: 2010年3月8日

适用范围: SharePoint Server 2010

如果您的自定义文档转换器需要自定义配置界面,则您可以创建和指定一个自定义的 .aspx 页来实现此目的。此页将替换 Microsoft SharePoint Server 2010 中包含的默认文档配置设置页。

备注

如果您只需在配置过程中从管理员处收集其他信息,则可以指定一个要在默认的文档配置设置页(包含在 SharePoint Server 2010 中)上承载的自定义的 .ascx 控件。通过此方法,您可以使用默认的文档转换器配置设置页,而不必开发一个替代窗体。有关详细信息,请参阅其他转换器设置控件

管理员可以使用自定义页为使用转换器的各个内容类型指定配置设置。当用户选择转换该内容类型的文档时,会将这些特定于内容类型的转换器设置传递给文档转换器。SharePoint Server 2010 中的默认转换器配置设置页包含可传递特定于内容类型的转换器设置的代码。

若要指定自定义的转换器配置设置页,请将文档转换器定义的 ConverterSettingsForContentType 元素设置为要使用的 .aspx 页的文件名。该元素是可选元素;如果您不将它加入到您的转换器定义中,则该转换器的转换器配置页将不可用。

有关文档转换器定义的详细信息,请参阅文档转换器定义架构

当用户导航到转换器配置设置页时,SharePoint Server 2010 会将下面的信息传递到该页:

  • ctype   表示用户要为其配置此转换器的内容类型的内容类型 ID。

  • Converter   表示用户要配置的转换器的 GUID。

  • OriginalSource   表示用户从其导航的页面的 URL。此上下文中未使用此参数,可以忽略。

    例如:

    http://example-ts/_layouts/ConverterSettings.aspx?ctype=0x0101&Converter=6dfdc5b4%2D2a28%2D4a06%2Db0c6%2Dad3901e3a807&OriginalSource=http%3A%2F%2Fexample%2Dts%2FDocuments%2FForms%2FAllItems%2Easpx

    您指定的页面必须包含执行以下操作的代码:

    1. 设置由页面收集到 XML 文档中的配置设置的格式。

      对于为文档转换后续处理提供必要的配置信息的转换器,它必须根据下面的架构将其配置设置存储在指定的内容类型中。

      <rca:RCAuthoringProperties xmlns:rca="urn:sharePointPublishingRcaProperties">
        <rca:Converter rca:guid="6dfdc5b4-2a28-4a06-b0c6-ad3901e3a807">
          <rca:property rca:type="InheritParentSettings">True</rca:property>
          <rca:property rca:type="SelectedPageLayout">30</rca:property>
          <rca:property rca:type="SelectedPageField">f55c4d88-1f2e-4ad9-
            aaa8-819af4ee7ee8</rca:property>
          <rca:property rca:type="SelectedStylesField">a932ec3f-94c1-48b1-
            b6dc-41aaa6eb7e54</rca:property>
          <rca:property 
            rca:type="CreatePageWithSourceDocument">True</rca:property>
          <rca:property 
            rca:type="AllowChangeLocationConfig">True</rca:property>
          <rca:property rca:type="ConfiguredPageLocation"></rca:property>
          <rca:property rca:type="CreateSynchronously">True</rca:property>
          <rca:property 
            rca:type="AllowChangeProcessingConfig">True</rca:property>
          <rca:property rca:type="ConverterSpecificSettings"></rca:property>
        </rca:Converter>
      </rca:RCAuthoringProperties>
      

      在前面的示例中,元素表示在默认的转换器配置设置页上可用的各种选项。ConverterSpecificSettings 元素表示特定于转换器的 .ascx 控件(如果存在)所写出的配置设置。有关详细信息,请参阅其他转换器设置控件。此外,ConfiguredPageLocation 元素为空,指定 SharePoint Server 2010 应使用当前网站。

    2. 将该配置 XML 作为 XMLDocument 节点写入相应的内容类型定义。

      例如,下面的代码在构造了相应的 XML 文档后将更新网站内容类型定义,如前面所示。

      // Delete the previous instance of this document if it already exists.
      myContentType.XmlDocuments.Delete(RcaPropertiesNamespaceUri);
      myContentType.XmlDocuments.Add(this.myXmlDocument);
      myContentType.Update();
      
      ' Delete the previous instance of this document if it already exists.
      myContentType.XmlDocuments.Delete(RcaPropertiesNamespaceUri)
      myContentType.XmlDocuments.Add(Me.myXmlDocument)
      myContentType.Update()
      

配置设置数据可以是文档转换器能解析的任何格式标准的 XML。SharePoint Server 2010 并不分析信息本身,而仅仅使您能够在内容类型定义中存储此 XML,以便随后可将它传递给文档转换器。

请注意,如果您指定了转换器配置设置页,就必须另外为用户界面指定一个自定义的 .aspx 页,以便调用此文档转换器。用于调用文档转换的默认页不会将任何配置设置传递给选定的转换器。有关详细信息,请参阅自定义转换设置页

承载自定义的转换器设置控件

调用文档转换器的页面必须包含执行此操作的代码,才能启用自定义的转换器设置控件。

例如,如果指定了一个自定义控件,则位于页面的 OnLoad 函数中的下列代码,会将自定义的转换器设置控件添加到该页面中。

下面的示例需要代码隐藏文件中的两个成员:

  • 类型为 System.Web.UI.Control、名为 customControl 的成员

  • 类型为 System.Web.UI.WebControls.PlaceHolder 的名为 customConverterControl 的成员,以及 .aspx 页上的相应占位符

    if (!String.IsNullOrEmpty(myTransformer.ConverterSpecificSettingsUI))
    {
      this.customControl = 
        LoadControl(myTransformer.ConverterSpecificSettingsUI);
      this.customConverterControl = this.customControl as 
        IDocumentConverterControl;
      if (this.customConverterControl != null)
      {
        this.converterSpecificControl.Controls.Add(this.customControl);
      }
    }
    
    If Not String.IsNullOrEmpty(myTransformer.ConverterSpecificSettingsUI) Then
      Me.customControl = LoadControl(myTransformer.ConverterSpecificSettingsUI)
      Me.customConverterControl = TryCast(Me.customControl, IDocumentConverterControl)
      If Me.customConverterControl IsNot Nothing Then
    Me.converterSpecificControl.Controls.Add(Me.customControl)
      End If
    End If
    

    下一步,代码应用自定义转换器设置控件的现有设置。

    // Set up the converter-specific control and retrieve the settings.
    if (this.customConverterControl != null)
    {
      this.customConverterControl.ContentType = this.CurrentContentType;
      this.customConverterControl.ConverterSettings = 
          this.effectiveRcaProperties.ConverterSpecificSettings; 
    }
    
    ' Set up the converter-specific control and retrieve the settings.
    If Me.customConverterControl IsNot Nothing Then
      Me.customConverterControl.ContentType = Me.CurrentContentType
      Me.customConverterControl.ConverterSettings = Me.effectiveRcaProperties.ConverterSpecificSettings
    End If
    

    最后,位于页面的 OnOK 函数中的下列代码示例,将自定义的转换器设置保存到网站内容类型定义。请注意,该代码将设置内容类型,以便为该控件提供详细的上下文信息。

    // Persist the converter-specific settings.
    if (this.converterSpecificControl.Controls.Count > 0)
    {
      if (this.customConverterControl != null)
      {
        this.customConverterControl.ContentType = this.CurrentContentType;
        this.myRcaProperties.ConverterSpecificSettings = 
          this.customConverterControl.ConverterSettings; 
    // Store this string in the content type properties as converter specific settings.
      }
    }
    
    ' Persist the converter-specific settings.
    If Me.converterSpecificControl.Controls.Count > 0 Then
      If Me.customConverterControl IsNot Nothing Then
    Me.customConverterControl.ContentType = Me.CurrentContentType
    Me.myRcaProperties.ConverterSpecificSettings = Me.customConverterControl.ConverterSettings
    ' Store this string in the content type properties as converter specific settings.
      End If
    End If
    

请参阅

概念

文档转换器概述

文档转换器

文档转换器部署

文档转换器定义架构

其他转换器设置控件

自定义转换设置页