SharePoint Offline form submission

Recently I came came across a following requirement

1) Site owner should e-mail an input fill form to an external user who is not in the network.

2) User fills the form and send it back to site owner

3) Site owner should be able to upload the form to the form library

4) All the metadata from the input form should be uploaded automatically

5) Ability for the site owner to edit the form using info-path


1) Create an input form template using MS Word

2) Map custom infopath schema using Word Content Control Tool Kit

3) Create a webpart with upload control

4) Use OpenXML libraries to read data from docx file

1) Create an input form template using MS Word:

Enable developer tools in Word  -> Options -> Customize Ribbon -> Developer

2013-08-17 14_14_02-Word Options

Design an input from using Content controls. A quick way to do this is to design the form layout using Infopath without any input controls, copy the layout in to word and add the content controls from developer pane


2) Map custom infopath schema using Word Content Control Tool Kit:

Since the metadata would be uploaded to form library and to provide infopath editable features, infopath schema is used here. Add all the fields to this schema.


<?xml version=”1.0″ encoding=”utf-8″?>
<?mso-application progid=”InfoPath.Document” versionProgid=”InfoPath.Document.3″?>
<my:myFields xmlns:xsi= ”” xmlns:my=”"
xmlns:xd=”" xml:lang=”en-US”>

Now use codeplex solution “word content control tool kit” to map the schema to the word template. Open the docx file using this tool, add the xml schema and map the input fields.

2013-08-17 14_15_53-NewHealthCareProviderForm_Physician.docx - Word 2007 Content Control Toolkit

3) Create a webpart with up:oad control

Now design a visual webpart with fileupload control


<asp:FileUpload ID="docxUpload" runat="server" /> </br></br>
<asp:Button ID="submitButton" runat="server" Text="Submit" />
<p><asp:Label ID="lblError" runat="server"></asp:Label></p>

Create Child controls:

protected override void CreateChildControls()
userControl = (UserControl)this.Page.LoadControl(ASCXPATH);
docxUpload = (System.Web.UI.WebControls.FileUpload)this.userControl.FindControl("docxUpload");
bSubmit = (System.Web.UI.WebControls.Button)this.userControl.FindControl("submitButton");
lblError = (System.Web.UI.WebControls.Label)this.userControl.FindControl("lblError");
bSubmit.Click += new EventHandler(submitButton_Click);


4) Use OpenXML libraries to read data from docx file:

On clicking the submit button, use openxml libraries (using DocumentFormat.OpenXml.Packaging) to read the custom xml and upload to the infopath form library

protected void submitButton_Click(object sender, EventArgs e)

lblError.Text = "";

#region MyRegion
 if (docxUpload.HasFile)

if (Path.GetExtension(docxUpload.FileName) == ".docx")

 using (WordprocessingDocument wdDoc = WordprocessingDocument.Open(docxUpload.PostedFile.InputStream,false))
 HashSet<OpenXmlPart> partList = new HashSet<OpenXmlPart>();
 MainDocumentPart mainPart = wdDoc.MainDocumentPart;
 foreach (CustomXmlPart part in mainPart.CustomXmlParts)

if (part.Uri.ToString() == "/customXml/item1.xml")

XmlDocument xmlDoc = new XmlDocument();
 XmlNamespaceManager ns = new XmlNamespaceManager(xmlDoc.CreateNavigator().NameTable);
 ns.AddNamespace("my", "");
 XmlNode recepientType = xmlDoc.SelectSingleNode("/my:myFields/my:RecipientType", ns);
 if (recepientType.InnerText == "1")
 fileName = xmlDoc.SelectSingleNode("/my:myFields/my:PhysicianInfo/my:PhysicianLastName", ns).InnerText + "_" + xmlDoc.SelectSingleNode("/my:myFields/my:PhysicianInfo/my:PhysicianFirstName", ns).InnerText + "_" + DateTime.Today.ToString("yyyy-MM-dd") + ".xml";

 fileName = xmlDoc.SelectSingleNode("/my:myFields/my:TeachingHospital/my:TeachingHospitalName", ns).InnerText + "_" + DateTime.Today.ToString("yyyy-MM-dd") + ".xml";

using (SPSite site = new SPSite(SPContext.Current.Site.ID))
 using (SPWeb web = site.OpenWeb(SPContext.Current.Web.ID))

web.AllowUnsafeUpdates = true;
 SPFolder frmFolder = web.GetFolder(docLib);
 SPFile spfile = frmFolder.Files.Add(fileName, part.GetStream());
 web.AllowUnsafeUpdates = false;






 lblError.Text = "please upload .docx extensions";

 lblError.Text = "please upload .docx extensions";


Add this webpart to the /Forms/AllItems.aspx in the form library. Now submit the word file from this webpart.