Export (0) Print
Expand All

How to: Verify a Batch of Form Templates

For the purposes of this task, the VerifyFormTemplate method of the FormTemplateCollection class is used to verify a form template listed in a text box. This is the same as using the Verify button on the Upload Form Template page of the SharePoint 3.0 Central Administration site.

The form contains the following: a FolderBrowserDialog control; a button which opens the FolderBrowserDialog; a text box that holds the location of the folder containing form templates to be verified; a button which executes the form template verificatio;, and a rich text box to display the form template verified and any converter messages.

NoteNote:

This topic assumes that Microsoft Visual Studio 2005 is installed on the Web front-end (WFE) or single farm server running InfoPath Forms Services.

Setup The Project

  1. Create a new Visual Basic Windows Application project in Microsoft Visual Studio 2005.

  2. On the Project menu, click Add Reference.

  3. On the .NET tab of the Add Reference dialog box, select Windows® SharePoint® Services, and click OK.

  4. On the Project menu, click Add Reference again.

  5. On the Browse tab of the Add Reference dialog box, browse to the Microsoft.Office.InfoPath.Server.dll assembly, typically located at C:\Program Files\Microsoft Office Servers\12.0\Bin\. Select the assembly and click OK.

Add Controls and Code to the Form

  1. Add the following controls to the form. These can be found in the All Windows Forms category of the Visual Studio Toolbox:

    • Two Button controls

    • A TextBox control

    • A RichTextBox control

  2. Rename the first button to "Pick a Folder" and the second button to "Verify Form Templates" by modifying the Text property of each button in the Properties Window.

  3. Reposition and resize the form and the controls until all text can be seen on the buttons and the RichTextBox control fills most of the form.

  4. On the View menu, click Code.

  5. Paste the code below into the code window, replacing all existing code.

  6. Click Form1.vb [Design] on the Window menu.

  7. In the Properties Window, click the drop-down list box and select Button1.

  8. In the Properties Window, click the Events button, which is typically the fourth button from the left in the row of buttons below the drop-down list box.

  9. In the Action section, click the drop-down for the Click event and select Button1_Click.

  10. In the Properties Window, click the drop-down list box and select Button2.

  11. In the Action section, click the drop-down for the Click event and select Button2_Click.

  12. On the File menu, click Save All.

  13. Press F5 to run the application.

Example

Use the procedures above to create a new Visual Basic Windows application that uses this code example to verify form templates in a folder, and to list any converter messages associated with each form template or messages indicating the form template is ready to be uploaded.

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
        'Show the folder browser dialog
        If FolderBrowserDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
            TextBox1.Text = FolderBrowserDialog1.SelectedPath
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim Directory As New IO.DirectoryInfo(TextBox1.Text)
        Dim AllFiles As IO.FileInfo() = Directory.GetFiles("*.xsn", IO.SearchOption.TopDirectoryOnly)
        Dim MyFile As IO.FileInfo
        Dim StrLog As String = ""
        Dim LocalFormsService As FormsService
        Dim LocalFarm As SPFarm
        Dim VerifyMessages As New ConverterMessageCollection
        Dim ConverterMsg As ConverterMessage
        Dim IntFileCount As Int16 = 0

        Try
            'Loop through each file
            For Each MyFile In AllFiles
                'Write the filename and path to the string
                StrLog = StrLog + MyFile.FullName.ToString() + Environment.NewLine
                LocalFarm = SPFarm.Local
                LocalFormsService = LocalFarm.Services.GetValue(Of FormsService)(FormsService.ServiceName)
                'Verify the form template
                VerifyMessages = FormTemplateCollection.VerifyFormTemplate(MyFile.FullName.ToString())
                'If there are no messages, display a message that the form template
                'is OK, otherwise loop through the messages and build the string
                If VerifyMessages.Count = 0 Then
                    StrLog = StrLog + "  There are no problems with this form template." + Environment.NewLine
                Else
                    For Each ConverterMsg In VerifyMessages
                        StrLog = StrLog + "  " + ConverterMsg.ShortMessage.ToString() + _
                        ": " + ConverterMsg.DetailedMessage.ToString() + Environment.NewLine
                    Next
                End If
                'Write the string to the rich text box
                RichTextBox1.Text = RichTextBox1.Text + StrLog
                RichTextBox1.Refresh()
                'Reset the string, adding a blank line between files
                StrLog = Environment.NewLine
                'Increment the file count
                IntFileCount = IntFileCount + 1
            Next
            'Show message that the files are done
            MessageBox.Show(IntFileCount.ToString() + " file(s) verified")
        Catch ex As Exception
            MessageBox.Show("An error occurred: " + ex.Message)
        End Try
    End Sub
End Class

If you need to process every form template in the main folder and any subfolder, change the IO.SearchOption.TopDirectoryOnly parameter to IO.SearchOption.AllDirectories.

If you need to upload form templates after verifying them, use the UploadFormTemplate method.

See Also

Community Additions

ADD
Show:
© 2014 Microsoft