How to: Quiesce a Form Template Selected From a List

For this task, a DataGridView control is populated with a list of the form templates that have been uploaded to the server by an administrator. This list corresponds to the list found on the Manage Form Templates page of the SharePoint 3.0 Central Administration site, and does not include user-deployed form templates.

The form requires two buttons and a DataGridView control. The first button sets up the data grid and then calls a routine to populate it. The second button quiesces the form template selected in the data grid and then calls a routine to refresh the data grid. Quiescing a form template blocks new sessions from being started and allows current sessions to expire over a specified time frame. See the Quiesce method for more information on form template quiescing.

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 C# 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 DataGridView control

  2. Rename the first button to "List all form templates" and the second button "Quiesce form template" 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 DataGridView 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. Replace WindowsApplication1 in the namespace WindowsApplication1 line with the namespace of your application. Your namespace can be found in the Solution Explorer and Class View windows.

  7. Click Form1.cs [Design] on the Window menu.

  8. In the Properties Window, click the drop-down list box and select button1.

  9. 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.

  10. In the Action section, click the drop-down for the Click event and select button1_Click.

  11. In the Properties Window, click the drop-down list box and select button2.

  12. In the Action section, click the drop-down for the Click event and select button2_Click.

  13. On the File menu, click Save All.

  14. Press F5 to run the form and debug the code.

Example

Use the procedures above to create a new Visual C# Windows application that uses this code example to list form templates on a server running InfoPath Forms Services and quiesce a form template selected from the list.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.SharePoint.Administration;
using Microsoft.Office.InfoPath.Server.Administration;

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //setup DataGridView1
            dataGridView1.ColumnCount = 4;
            dataGridView1.SelectionMode =
            DataGridViewSelectionMode.FullRowSelect;
            dataGridView1.ReadOnly = true;
            dataGridView1.MultiSelect = false;
            dataGridView1.Columns[0].Name = "Form Name";
            dataGridView1.Columns[1].Name = "Form ID";
            dataGridView1.Columns[2].Name = "Status";
            dataGridView1.Columns[3].Name = "Locale";
            //populate DataGridView1
            populateDataGrid();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            FormsService localFormsService;
            SPFarm localFarm = SPFarm.Local;
            
            try
            {
                localFormsService = localFarm.Services.GetValue<FormsService>(FormsService.ServiceName);
                //get the selected row
                DataGridViewSelectedCellCollection dgvsc = dataGridView1.SelectedCells;
                //get the FormID from the selected cells
                string fTempToQuiesce = dgvsc[1].Value.ToString();
                //quiesce the form template
                TimeSpan ftQuiesce = new TimeSpan(600000000); //1 minute
                localFormsService.FormTemplates.Item(fTempToQuiesce).Quiesce(ftQuiesce);
                //populate DataGridView1 again to show updated status
                populateDataGrid();
            }
            catch (Exception ex)
            {
                MessageBox.Show("An error occurred: " + ex.Message.ToString());
            }
        }

        private void populateDataGrid()
        {
            FormsService localFormsService;
            SPFarm localFarm = SPFarm.Local;

            //clear all rows if DataGridView1 has already been populated
            if (dataGridView1.Rows.Count > 0)
            {
                dataGridView1.Rows.Clear();
            }

            try
            {
                localFormsService = localFarm.Services.GetValue<FormsService>(FormsService.ServiceName);
                foreach (FormTemplate fTemplate in localFormsService.FormTemplates)
                {
                    //add each form template to the DataGridView1
                    dataGridView1.Rows.Add(fTemplate.DisplayName.ToString(), fTemplate.FormId.ToString(), fTemplate.QuiesceStatus.ToString(), fTemplate.Locale.ToString());
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("An error occurred: " + ex.Message.ToString());
            }
        }
    }
}

See Also

Community Additions

ADD
Show: