Introduction
Using Aspose.Form for .NET, developers can load and view InfoPath forms in web browsers. Once the InfoPath form is loaded, users can fill forms easily. However, developers can access the data filled in forms by users on server side using Aspose.Form for .NET API. Let's take a look, how can we do it?
Accessing XML Data of InfoPath Forms
There are two ways to access data of InfoPath forms as shown below:
Using XML String
Aspose.Form for .NET provides XmlFormView class that represents InfoPath form control. Using this control, InfoPath forms are viewed in browser. This control provides XmlDataString property that can be used by developers to access the InfoPath form data as an XML string. This way, complete InfoPath data is retrieved by developers as a single string object that can be either stored in database directly or viewed in browser in a textbox as shown below in an example.
Example
[C#]
//Viewing the XML based form data in a textbox
TextBox1.Value = XmlFormView1.XmlDataString;
[VB.NET]
'Viewing the XML based form data in a textbox
TextBox1.Value = XmlFormView1.XmlDataString
It's also possible to download the complete XML data of InfoPath form as an XML file as shown below in the code snippet.
Example
[C#]
private void Button1_Click(object sender, System.EventArgs e)
{
Page.Response.Clear();
Page.Response.ContentType = "application/x-msdownload";
Page.Response.AddHeader("Content-Disposition", "attachment; filename=GeneratedData.xml");
Page.Response.Write(XmlFormView1.XmlDataString);
Page.Response.End();
}
[VB.NET]
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
Page.Response.Clear()
Page.Response.ContentType = "application/x-msdownload"
Page.Response.AddHeader("Content-Disposition", "attachment; filename=GeneratedData.xml")
Page.Response.Write(XmlFormView1.XmlDataString)
Page.Response.End()
End Sub
Using XML Node Object
Developers can also access form data using XmlDataNode property of FormControl class. It can also be used in the same ways as we already discussed above while talking about the use of XmlDataString property. However, the major difference is that XmlDataNode property provides InfoPath form data as an XmlNode object. So, developers can traverse through all XML data nodes using this approach. XMLNode object gives more control and flexibility to developers to control and manage form data in their own desired manner.