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

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

适用范围: SharePoint Server 2010

为完成此任务,可使用 FormsService 类及其关联成员来设置"配置 InfoPath Forms Services"页上的大多数项的默认值,此页可以在"SharePoint 2010 管理中心"网站的"一般应用程序设置"页上找到。

您为此项目创建的表单包含一个按钮和一个格式文本框。当执行此表单时,将使用用于设置某个配置属性的类成员的名称以及每个成员的旧值和新值来填充格式文本框。

备注

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

设置项目

  1. 在 Microsoft Visual Studio 中创建一个新的 Visual Basic"Windows 窗体应用程序"项目。

  2. 在"项目"菜单上,单击"添加引用"。

  3. 在"添加引用"对话框的".NET"选项卡上,选择"Microsoft SharePoint Foundation",然后单击"确定"。(如果"Microsoft SharePoint Foundation"在".NET"选项卡上不可用,则在"浏览"选项卡上,浏览到C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI\,选择 Microsoft.SharePoint.dll 程序集,然后单击"确定"。)

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

  5. 在"添加引用"对话框的"浏览"选项卡上,浏览到 C:\Program Files\Microsoft Office Servers\14.0\Bin\,选择 Microsoft.Office.InfoPath.Server.dll 程序集,然后单击"确定"。

向表单中添加控件和代码

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

    • 一个"Button"控件

    • 一个"RichTextBox"控件。

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

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

  4. 在"视图"菜单上,单击"代码"。

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

  6. 在"窗口"菜单上单击"Form1.vb [设计]"。

  7. 在"属性窗口"中,单击下拉列表,然后选择"Button1"。

  8. 在"属性窗口"中,单击"Events"按钮,此按钮通常是下拉列表下方的按钮行中左起的第四个按钮。

  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 管理任务