如何:记录和重置 InfoPath Forms Services 配置设置

为完成此任务,可使用 FormsService 类及其关联成员来设置“SharePoint 3.0 管理中心”网站中“配置 InfoPath Forms Services”****页上大多数项的默认值。

该表单包含一个按钮和一个格式文本框。执行表单时,将以用于设置配置属性的类成员的名称以及每个成员的旧值和新值填充此格式文本框。

备注

本主题假定 Web 前端 (WFE) 或运行 InfoPath Forms Services 的单个场服务器上安装了 Microsoft Visual Studio 2005。

安装项目

  1. 在 Microsoft Visual Studio 2005 中创建一个新的“Visual Basic Windows 应用程序”****项目。

  2. 在“项目”菜单上,单击“添加引用”****。

  3. 在“添加引用”对话框的“.NET”选项卡上,选择“Windows® SharePoint® Services”,再单击“确定”

  4. 在“项目”菜单上,再次单击“添加引用”****。

  5. 在“添加引用”对话框的“浏览”****选项卡上,浏览到通常位于 C:\Program Files\Microsoft Office Servers\12.0\Bin\ 中的 Microsoft.Office.InfoPath.Server.dll 程序集。选择该程序集,再单击“确定”。

向表单中添加控件和代码

  1. 将下列控件添加到表单中。在 Visual Studio“工具箱”****的“所有 Windows 窗体”类别中可以找到这些控件:

    • 一个“Button”****控件

    • 一个“RichTextBox”控件。

  2. 修改“属性窗口”****中按钮的“文本”属性,以将该按钮重命名为“列出和重置配置设置”。

  3. 重新定位表单和控件并调整其大小,直到可在按钮上看到所有文本,且“RichTextBox”****控件填充了表单的大部分空间。

  4. 在“视图”菜单上,单击“代码”****。

  5. 将下面的代码粘贴到代码窗口中,以替换所有现有代码。

  6. 在“窗口”菜单上单击“Form1.vb [Design]”****。

  7. 在“属性窗口”中,单击下拉列表框并选择“Button1”****。

  8. 在“属性窗口”中,单击“事件”****按钮,此按钮通常是下拉列表框下方按钮行中左边第四个按钮。

  9. 在“操作”部分,单击“Click”****事件的相应下拉框并选择“Button1_Click”。

  10. 在****“文件”菜单上单击“全部保存”。

  11. 按 F5 运行应用程序。

示例

通过上面的步骤可创建新的 Visual Basic Windows 应用程序,此应用程序使用下面的代码示例来记录和重置 InfoPath Forms Services 配置设置。

Imports Microsoft.SharePoint.Administration
Imports Microsoft.Office.InfoPath.Server.Administration

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim LocalFormsService As FormsService
        Dim LocalFarm As SPFarm = SPFarm.Local
        Dim StrLog As String = ""

        Try
            LocalFormsService = LocalFarm.Services.GetValue(Of FormsService)(FormsService.ServiceName)
            'Build a string with the old a new value of each property
            With LocalFormsService
                StrLog = StrLog + "ActiveSessionsTimeout changed from " + _
                .ActiveSessionsTimeout.ToString() + " to 1440." + Environment.NewLine
                .ActiveSessionsTimeout = 1440

                StrLog = StrLog + "AllowEmbeddedSqlForDataConnections changed from " + _
                .AllowEmbeddedSqlForDataConnections.ToString() + " to False." + Environment.NewLine
                .AllowEmbeddedSqlForDataConnections = False

                StrLog = StrLog + "AllowUdcAuthenticationForDataConnections changed from " + _
                .AllowUdcAuthenticationForDataConnections.ToString() + " to False." + Environment.NewLine
                .AllowUdcAuthenticationForDataConnections = False

                StrLog = StrLog + "AllowUserFormBrowserEnabling changed from " + _
                .AllowUserFormBrowserEnabling.ToString() + " to True." + Environment.NewLine
                .AllowUserFormBrowserEnabling = True

                StrLog = StrLog + "AllowUserFormBrowserRendering changed from " + _
                .AllowUserFormBrowserRendering.ToString() + " to True." + Environment.NewLine
                .AllowUserFormBrowserRendering = True

                StrLog = StrLog + "AllowUserFormCrossDomainDataConnections changed from " + _
                .AllowUserFormCrossDomainDataConnections.ToString() + " to False." + Environment.NewLine
                .AllowUserFormCrossDomainDataConnections = False

                StrLog = StrLog + "AllowViewState changed from " + _
                .AllowViewState.ToString() + " to False." + Environment.NewLine
                .AllowViewState = False

                StrLog = StrLog + "DefaultDataConnectionTimeout changed from " + _
                .DefaultDataConnectionTimeout.ToString() + " to 10000." + Environment.NewLine
                .DefaultDataConnectionTimeout = 10000

                StrLog = StrLog + "MaxDataConnectionResponseSize changed from " + _
                .MaxDataConnectionResponseSize.ToString() + " to 1500." + Environment.NewLine
                .MaxDataConnectionResponseSize = 1500

                StrLog = StrLog + "MaxDataConnectionTimeout changed from " + _
                .MaxDataConnectionTimeout.ToString() + " to 20000." + Environment.NewLine
                .MaxDataConnectionTimeout = 20000

                StrLog = StrLog + "MaxPostbacksPerSession changed from " + _
                .MaxPostbacksPerSession.ToString() + " to 75." + Environment.NewLine
                .MaxPostbacksPerSession = 75

                StrLog = StrLog + "MaxSizeOfFormSessionState changed from " + _
                .MaxSizeOfFormSessionState.ToString() + " to 4194304." + Environment.NewLine
                .MaxSizeOfFormSessionState = 4194304

                StrLog = StrLog + "MaxUserActionsPerPostback changed from " + _
                .MaxUserActionsPerPostback.ToString() + " to 200." + Environment.NewLine
                .MaxUserActionsPerPostback = 200

                StrLog = StrLog + "RequireSslForDataConnections changed from " + _
                .RequireSslForDataConnections.ToString() + " to False." + Environment.NewLine
                .RequireSslForDataConnections = False

                StrLog = StrLog + "ViewStateThreshold changed from " + _
                .ViewStateThreshold.ToString() + " to 40960." + Environment.NewLine
                .ViewStateThreshold = 40960
            End With
            'Populate the rich text box with the log
            RichTextBox1.Text = StrLog
        Catch ex As Exception
            MessageBox.Show("An error has occurred: " + ex.Message.ToString())
        End Try

    End Sub
End Class

另请参阅

其他资源

开发 Windows 应用程序以执行 InfoPath Forms Services 管理任务