フォーム テンプレートを一括して検証する
最終更新日: 2010年3月30日
適用対象: SharePoint Server 2010
このタスクのためには、FormTemplateCollection クラスの VerifyFormTemplate メソッドを使用して、テキスト ボックスの一覧で示されているフォーム テンプレートを確認します。これは、SharePoint 2010 サーバーの全体管理サイトの [フォーム テンプレートのアップロード] ページにある [確認] ボタンを使用するのと同じです。
このプロジェクト用に作成するフォームには、FolderBrowserDialog コントロール、FolderBrowserDialog を開くボタン、検証対象のフォーム テンプレートを含むフォルダーの場所を保持するテキスト ボックス、フォーム テンプレートの確認を実行するボタン、および確認されたフォーム テンプレートとコンバーターのメッセージを表示するリッチ テキスト ボックスが含まれます。
注意
このトピックは、InfoPath Forms Services を実行している Web フロントエンド (WFE) またはシングル ファーム サーバーに、Microsoft Visual Studio がインストールされていることを前提とします。
プロジェクトをセットアップするには
Microsoft Visual Studio で、新しい Visual Basic Windows フォーム アプリケーション プロジェクトを作成します。
[プロジェクト] メニューの [参照の追加] をクリックします。
[参照の追加] ダイアログ ボックスの [.NET] タブで、[Microsoft.SharePoint Foundation] を選択し、[OK] をクリックします ([Microsoft SharePoint Foundation] が [.NET] タブにない場合、[参照] タブで、C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI\ を参照し、Microsoft.SharePoint.dll アセンブリを選択して、次に [OK] をクリックします)。
もう一度 [プロジェクト] メニューの [参照の追加] をクリックします。
[参照の追加] ダイアログ ボックスの [参照] タブで、C:\Program Files\Microsoft Office Servers\14.0\Bin\ を参照し、Microsoft.Office.InfoPath.Server.dll アセンブリを選択して、[OK] をクリックします。
フォームにコントロールとコードを追加するには
フォームに以下のコントロールを追加します。これらのコントロールは、Visual Studio の [ツールボックス] の [すべての Windows フォーム] カテゴリに表示されます。
2 つの Button コントロール
1 つの TextBox コントロール
1 つの RichTextBox コントロール
[プロパティ ウィンドウ] で各ボタンの Text プロパティを変更して、最初のボタンの名前を "Pick a Folder" に、2 番目のボタンの名前を "Verify Form Templates" に変更します。
ボタン上にすべてのテキストが表示され、フォームの大部分の領域が RichTextBox コントロールによって占められるように、フォームとコントロールの配置およびサイズを調整します。
[表示] メニューの [コード] をクリックします。
以下のコードをコード ウィンドウに貼り付けて、既存のコードをすべて置き換えます。
[ウィンドウ] メニューの [Form1.vb [デザイン]] をクリックします。
[プロパティ] ウィンドウで、ドロップダウン リストをクリックし、[Button1] をクリックします。
[プロパティ] ウィンドウで [イベント] ボタンをクリックします。このボタンは、通常、ドロップダウン リストの下に並んでいるボタンの左から 4 番目のボタンです。
[アクション] セクションで、Click イベントのボックスをクリックし、[Button1_Click] をクリックします。
[プロパティ] ウィンドウで、ドロップダウン リストをクリックし、[button2] をクリックします。
[アクション] セクションで、Click イベントのボックスをクリックし、[Button2_Click] をクリックします。
[ファイル] メニューの [すべて保存] をクリックします。
F5 キーを押してアプリケーションを実行します。
例
以下のコード例を使用する新しい Visual Basic Windows アプリケーションを作成してフォルダー内のフォーム テンプレートを確認し、各フォーム テンプレートに関連するコンバーターのメッセージまたはフォーム テンプレートがアップロードできる状態であることを示すメッセージを一覧で表示するには、前記の手順を使用します。
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
メイン フォルダーとすべてのサブフォルダーにあるすべてのフォーム テンプレートを処理する必要がある場合は、IO.SearchOption.TopDirectoryOnly パラメーターを IO.SearchOption.AllDirectories に変更します。
確認後にフォーム テンプレートをアップロードする必要がある場合は、UploadFormTemplate メソッドを使用します。