Printing InfoPath 2007 Web-Based Forms to PDF
page 5 of 8
by S.Y.M. Wong-A-Ton
Feedback
Average Rating: 
Views (Total / Last 10 Days): 47600/ 77

Creating a Custom ASP.NET Page to Host a Form Template

Once you have published the form template to a SharePoint server running InfoPath Forms Services, you must create a custom ASP.NET page as described in the article Hosting the InfoPath 2007 Form Editing Environment in a Custom Web Form to host the form template and then follow the instructions in "Step 2: Hooking Up the NotifyHost Event to an Event Handler" in the article How to execute JScript code from an InfoPath 2007 browser-enabled form template to hook up the NotifyHost event of the XmlFormView control to an event handler in the ASP.NET page. You must then write code in this event handler to:

3.    Retrieve the XML of the form and store it in a Session variable.

4.    Navigate to the ASP.NET page that prints the form to PDF.

Listing 2 shows how you can retrieve the XML of the form, store the XML in a Session variable named XMLForm, and then use the Redirect method of the Response object to navigate to the ASP.NET page that prints the form to PDF. XmlFormView1 is the name of the XmlFormView control that is hosting the InfoPath form on the ASP.NET page and XmlFormView1_NotifyHost is the name of the event handler that is hooked up to the NotifyHost event of the XmlFormView control. PrintToPDF.aspx is the name of the ASP.NET page that prints the form to PDF. In this example PrintToPDF.aspx is located in a folder named CustomPage under the root of a site.

Listing 2: Retrieving and storing the XML of a form and redirecting to a page that prints the form

protected void XmlFormView1_NotifyHost(object sender, 
                                       NotifyHostEventArgs e)
{
    if (XmlFormView1 != null && XmlFormView1.XmlForm != null 
        && XmlFormView1.XmlForm.MainDataSource != null)
    {
        // Retrieve the XML of the form
        string xml =
        XmlFormView1.XmlForm.MainDataSource.CreateNavigator().OuterXml;
 
        // Store the XML of the form in an XmlForm Session variable
        if (Session["XmlForm"] != null)
        {
            Session.Add("XmlForm", xml);
        }
        else
        {
            Session["XmlForm"= xml;
        }
 
         // Redirect to the page that prints the form to PDF
        Response.Redirect("~/CustomPage/PrintToPDF.aspx");
    }
 }

View Entire Article

User Comments

No comments posted yet.






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-03-29 1:38:30 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search