Forum Community.
I'm using Microsoft InfoPath, bundled with Microsoft Office Professional Plus 2010. I created a web browser form (*.xsn). Using the Visual Studio Tools for Applications (VSTA) feature in InfoPath, I added C# managed code behind a button; this button is supposed to create a PDF document using the iTextSharp Dll. Every part of my program "finally" works; however, InfoPath does not recognize references to "Response". My program only works with responses to "Response" commented out. Can anyone tell me what class/DLL I must add to my project in order for my form to compile properly with the "Response" references? The code containing the references to "Response" is listed below:
private void GeneratePDF()
{
// Retrieve XML of InfoPath form
XPathNavigator root = this.MainDataSource.CreateNavigator();
string xml = root.SelectSingleNode("/my:myFields", this.NamespaceManager).OuterXml;
// Load XML of InfoPath form into an XmlDocument object
XmlDocument xmlForm = new XmlDocument();
xmlForm.LoadXml(xml);
// Add the 'my' namespace of the form to an XmlNamespaceManager object
XmlNamespaceManager xmlNameSpaceMgr =
new XmlNamespaceManager(
new NameTable());
xmlNameSpaceMgr.AddNamespace("my", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-10-02T08:59:49");
// Retrieve the values of the InfoPath form fields using XPath
String agency = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:name_of_agency", NamespaceManager).Value;
String period = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:for_the_period", NamespaceManager).Value;
String org_unit = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:organization_unit", NamespaceManager).Value;
// Using iTextSharp to construct a PDF document
// Create a document-object
Document document = new Document(PageSize.A4);
// Create a writer that listens to the document
// and directs a XML-stream to a MemoryStream
using (MemoryStream ms = new MemoryStream())
{
PdfWriter.GetInstance(document, ms);
document.Open();
Font defaultFont = FontFactory.GetFont(
FontFactory.HELVETICA, 10, Font.NORMAL);
Font labelFont = FontFactory.GetFont(
FontFactory.HELVETICA, 10, Font.BOLD);
// Add agency
Paragraph paragraph = new Paragraph(15F);
paragraph.Add(new Chunk("Name of Agency: ", labelFont));
paragraph.Add(new Chunk(agency, defaultFont));
document.Add(paragraph);
// Add period
paragraph = new Paragraph(15F);
paragraph.Add(new Chunk("For the Period: ", labelFont));
paragraph.Add(new Chunk(period, defaultFont));
document.Add(paragraph);
// Add org_unit
paragraph = new Paragraph(15F);
paragraph.Add(new Chunk("Organization Unit: ", labelFont));
paragraph.Add(new Chunk(org_unit, defaultFont));
document.Add(paragraph);
document.Close();
// Return the InfoPath form as a PDF document
byte[] data = ms.ToArray();
//Response.Clear();
//Response.ClearHeaders();
//Response.ClearContent();
//Response.Buffer = true;
//Response.ContentType = "application/pdf";
//Response.BinaryWrite(data);
//Response.End();
ms.Close();
}
}
public void CTRL53_5_Clicked(object sender, ClickedEventArgs e)
{
GeneratePDF();
}
The DLL's currently linked to my form are listed below:
using Microsoft.Office.InfoPath;
using System;
using System.Xml;
using System.Xml.XPath;
using System.Text;
using System.IO;
using System.Security.Cryptography;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Diagnostics;
using iTextSharp.text;
using iTextSharp.text.pdf;
Thanks in advance for your help.
~Woodrow