Submitting data from an PDF Form to MS SharePoint
I have heard a few of our customers mention that they have SharePoint and LiveCycle ES but there seems to be a knowledge gap in how the two can be used together. Recently, we posted a whitepaper on Devnet. This whitepaper provides an excellent overview of the integration possibilities and added-value touch points. But the bottom line is that samples are what make the IT world turn. So, I decided that I would create a couple of quick samples that would demonstrate some of the low hanging fruit available. The problem is, where to start??? As if it was a sign, I stumbled on an Adobe forums post where someone was trying to submit data from a PDF form to SharePoint.
The key to handle a custom submission in SharePoint is to create a custom handler. Sounds worse than it actually is. It's actually very simple to get this working. Here is a link to a good MSDN article on how to create custom handlers (ashx) for Sharepoint 3.0:
http://msdn.microsoft.com/en-us/library/bb457204.aspx. From this article, I was able to create a custom handler that accepts an XML post from a PDF form. The handler then parses the submitted XML and extract some key values. Since this is a sample, I took the liberty to hard-code some of the logic to keep things simple :). Using the SPList API, I create a new list entry (A custom list I created in SharePoint called ‘Purchase Order’). Since the list I created had custom columns (Total, date, ordered by), I pump the data extracted from the XML submission into the desired columns. Finally, I attach the submitted XML document to the list entry.
As for the PDF Form, all you have to do is edit the form in Adobe Designer, configure the submit button on your form to submit XML or XDP data, and point the submission to your custom handler (ex: http://mysharepointserver/_layouts/SP_PDFSubmitHandler.ashx).
The screenshot below shows what the result of the submission looks like.
This is a snapshot of the the Custom List:
This is a snapshot of the item detail of a submission
Comments
Help!!!! Mycompany uses LiveCycle forms. We also have a sharepoint site. The development for both has fallen to me. :) I have been searching and searching for information on how to populate sharepoint lists from adobe forms. So I was excited to find this blog. When I tried to create my own handler I get an error that a root element is missing. Here is my code:
using System;
using System.Web;
using Microsoft.SharePoint;
using System.Xml;
public class HelloHttpHandler : IHttpHandler {
public void ProcessRequest (HttpContext context) {
SPSite site = SPContext.Current.Site;
SPWeb web = site.OpenWeb();
try
{
string rawXML = "";
XmlTextReader reader = new XmlTextReader(context.Request.InputStream);
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(reader);
string _xmlString = xmlDoc.InnerXml;
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
string _fileTime = DateTime.Now.ToFileTime().ToString();
byte[] docAsBytes = encoding.GetBytes(_xmlString);
//Insert Document
web.AllowUnsafeUpdates = true;
SPList list = web.Lists["Campaign Status Tracker"];
SPListItem item = list.Items.Add();
item["Campaign Name"] = xmlDoc.GetElementsByTagName("txtCampName").Item(0).InnerText;
item["Campaign Owner"] = xmlDoc.GetElementsByTagName("txtCampOwner").Item(0).InnerText;
item["Product Line"] = xmlDoc.GetElementsByTagName("cboProdLine").Item(0).InnerText;
item["Start Date"] = xmlDoc.GetElementsByTagName("dteStart").Item(0).InnerText;
item["Duration"] = xmlDoc.GetElementsByTagName("numDur").Item(0).InnerText;
item["Target End Date"] = xmlDoc.GetElementsByTagName("dteTarEndr").Item(0).InnerText;
item["Exposure"] = xmlDoc.GetElementsByTagName("numExp").Item(0).InnerText;
item["Actual End Date"] = xmlDoc.GetElementsByTagName("dteActEnd").Item(0).InnerText;
item["Campaign Vehicle"] = xmlDoc.GetElementsByTagName("cboCampVeh").Item(0).InnerText;
item["Campaign Budget"] = xmlDoc.GetElementsByTagName("numCampBud").Item(0).InnerText;
item["Balance"] = xmlDoc.GetElementsByTagName("numBal").Item(0).InnerText;
item["Budget Spent"] = xmlDoc.GetElementsByTagName("numTotExp").Item(0).InnerText;
item["Percent Spent"] = xmlDoc.GetElementsByTagName("numPercentSpent").Item(0).InnerText;
item["Total Responses"] = xmlDoc.GetElementsByTagName("numTotResp").Item(0).InnerText;
item["Total Actions"] = xmlDoc.GetElementsByTagName("numTotAction").Item(0).InnerText;
item["Total Sales"] = xmlDoc.GetElementsByTagName("numTotSales").Item(0).InnerText;
item["Total Amount Sales"] = xmlDoc.GetElementsByTagName("numTotSaleAmt").Item(0).InnerText;
item["Response Rate"] = xmlDoc.GetElementsByTagName("numRespRate").Item(0).InnerText;
item["Action Rate"] = xmlDoc.GetElementsByTagName("numActRate").Item(0).InnerText;
item["Conversion Rate"] = xmlDoc.GetElementsByTagName("numConvRate").Item(0).InnerText;
item["Cost p/Response"] = xmlDoc.GetElementsByTagName("numCostResp").Item(0).InnerText;
item["Cost p/Action"] = xmlDoc.GetElementsByTagName("numCostAct").Item(0).InnerText;
item["Avg Purchase Value"] = xmlDoc.GetElementsByTagName("numAvgPurVal").Item(0).InnerText;
item.Update();
//Redirect the browser to the Campaign Tracker list so we can see our submisison.
context.Response.Redirect("http://team.mysite.net/sales/marketing/Lists/Campaign%20Status%20Tracker/Allitemsg.aspx");
}
catch (Exception ex)
{
context.Response.Write(ex.Message);
}
}
public bool IsReusable {
get {
return false;
}
}
}
My sharepoint runs on server 2008. Can you see what I am missing, or what I did wrong? I am learning by doing so I may have totally missed something.
Any help is greatly appreciated!
Trudy
Posted by: Trudy Hutzler | May 4, 2009 9:14 PM
Hi, I would like to try the handler above, but I cannot find the "_layouts" folder to store the handler in.
Am I missing the folder or is it something I create? Wouldn't I want it in the folder where I want the form stored?
thanks.
Posted by: Barry Walls | June 10, 2009 12:29 PM