如何:在部署前验证表单模板

上次修改时间: 2010年7月6日

适用范围: SharePoint Server 2010

可在将与浏览器兼容的 InfoPath 表单模板部署到运行 InfoPath Forms Services 的服务器之前对其进行验证。通过验证表单模板,可以确保在部署之前就解决与部署有关的问题。与使用 InfoPath 设计用户界面的"检查设计方案"任务窗格的"在服务器上验证"选项一样,可以通过"SharePoint 2010 管理中心"网站或通过使用 FormTemplateCollection() 类的 VerifyFormTemplate 方法的代码来完成验证。

使用 SharePoint 管理中心网站验证表单模板

  1. 使用"发布向导"准备一个需要经过管理员批准才能发布的表单模板。有关执行此操作的步骤,请参阅如何:部署包含需要完全信任的表单代码的表单模板

  2. 打开"SharePoint 2010 管理中心"网站。

    备注

    您必须是"服务器场管理员"组的成员,才能完成此步骤和剩余步骤。

  3. 在"一般应用程序设置"下单击"管理表单模板"链接。

  4. 单击页面顶端附近的"上载表单模板"链接。

  5. 单击"浏览"按钮以打开一个对话框,然后键入已发布表单模板的路径。

  6. 单击"验证"按钮来验证表单模板是否已作好上载到服务器的准备。

使用 FormCollection 类的 VerifyFormTemplate 方法验证表单模板

  1. 使用"发布向导"准备一个需要经过管理员批准才能发布的表单模板。有关执行此操作的步骤,请参阅如何:部署包含需要完全信任的表单代码的表单模板中的第一步。

  2. 打开 Visual Studio。

    备注

    这些步骤要求在运行 InfoPath Forms Services 的计算机上安装 Visual Studio。

  3. 使用 Visual Basic 或 C# 新建一个"控制台应用程序"。

  4. 在"解决方案资源管理器"中右键单击该项目,然后单击"添加引用"。

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

  6. 重复步骤 3,并在"添加引用"对话框中单击"浏览"选项卡。

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

  8. 根据您在步骤 2 中选择的语言,将下面的代码示例复制并粘贴到代码窗口中。

  9. 将 SolutionPath 变量更改为发布经管理员批准的表单模板的位置。

  10. 保存该项目,按 F5 键调试并运行该代码。

转换器消息及任何其他消息的计数将显示在控制台窗口中。

示例

以下代码示例使用 VerifyFormTemplate 方法将转换器消息(如果有)显示在控制台窗口中。表单模板的位置存储在变量 SolutionPath 中,且应更改为您要验证的表单模板的路径。

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

Module Module1

    Sub Main()
        Dim LocalFormsService As FormsService
        Dim LocalFarm As SPFarm
        Dim SolutionPath As String = "C:\FormTemplates\FormTemplate.xsn"
        Dim VerifyMessages As New ConverterMessageCollection
        Dim ConverterMsg As ConverterMessage
        Try
            LocalFarm = SPFarm.Local
            LocalFormsService = LocalFarm.Services.GetValue(Of FormsService)(FormsService.ServiceName)
            VerifyMessages = FormTemplateCollection.VerifyFormTemplate(SolutionPath)
            Console.WriteLine("# of messages: " + VerifyMessages.Count.ToString())
            For Each ConverterMsg In VerifyMessages
                Console.WriteLine(ConverterMsg.ShortMessage.ToString() & ": " & ConverterMsg.DetailedMessage.ToString())
            Next
            Console.Write("Press Enter to Continue")
            Console.ReadLine()
        Catch ex As Exception
            Console.WriteLine("Error: " + ex.Message)
            Console.Write("Press Enter to Continue")
            Console.ReadLine()
        End Try

    End Sub

End Module
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint.Administration;
using Microsoft.Office.InfoPath.Server.Administration;

namespace VerifyFormTemplate
{
    class Program
    {
        static void Main(string[] args)
        {
            FormsService localFormsService;
            SPFarm localFarm = SPFarm.Local;
            string solutionPath = "C:\\FormTemplates\\FormTemplate.xsn";
            ConverterMessageCollection verifyMessages;
            try
            {
                localFormsService = localFarm.Services.GetValue<FormsService>(FormsService.ServiceName);
                verifyMessages = FormTemplateCollection.VerifyFormTemplate(solutionPath);
                Console.WriteLine("# of messages: " + verifyMessages.Count.ToString());
                foreach (ConverterMessage convMessage in verifyMessages)
                {
                    Console.WriteLine(convMessage.ShortMessage.ToString() + ": " + convMessage.DetailedMessage.ToString());
                }
                Console.Write("Press Enter to Continue");
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
                Console.Write("Press Enter to Continue");
                Console.ReadLine();
            }
        }
    }
}

请参阅

任务

如何:验证一批表单模板