Integrating InfoPath Forms
About the Speaker….
Paul Baker
Director of Educational Innovation
Perse School, Cambridge
http://www.perse.co.uk
[email protected]
The Perse School regularly features in the top
25 schools nationally. Our commitment to
producing happy and successful students
leads to positive, focused work on how ICT
can contribute to learning and strong
About the Speaker….
Paul Baker
p_d_baker
mathstweets
I‟m interested in
SharePoint
Virtual Learning Tools
SCORM Learning Banks
Microsoft Reporting Services
Parent Communication
A long way to go
….forward together
EASN : East Anglia SharePoint Network for
schools
http://www.easn.org.uk
Sharing ideas and work in progress
Sharing between independent and state
schools
Content Slide
an application used to develop XML-based data entry
forms.
To use InfoPath to fill in a form, a user must have a
designer develop an InfoPath template first.
The most common usage of InfoPath is to integrate it
with Microsoft SharePoint.
In SharePoint, a "Form Library" can be created and
developed by using InfoPath. InfoPath fields will be
exported as "Columns" in the library.
Content Slide
InfoPath 2007
Included in Office 2007 Ultimate and the volume license
editions, Professional Plus, Enterprise, and sold separately
InfoPath 2010
Included in Office 2010 Professional Plus
WSS/SharePoint 2007/2010 to host “form
libraries”
SharePoint Enterprise
for InfoPath form services functionality.
(Or as the separate Office Forms Server 2007 product.)
Designed using Controls
Drag and
Drop
Published
Designing a form means defining an
xml structure
and
a
user interface
to interact with that structure.
Behind the scenes the structure is defined using
a
schema
InfoPath calls that structure and the data that it
contains when being completed the “
main data
source
”
InfoPath is XML-based
When a form is completed and saved then that data is
saved as a single xml file, preferably into a sharepoint
forms library that can read the contents of the file
directly.
That xml file contains a reference to the location of
the xsn file so that if it is opened again it can display
the data in the original view.
In a SharePoint forms library, content of xml
documents can be collated and displayed in
columns in real time.
Data is well defined
Data can be accessed and transformed or
summarised easily
Validation can be applied
Routing can be applied conditionally
InfoPath is XML-based
PLACE DEMO TITLE HERE
Designing an InfoPath form.
Adding validation and configuring views.
Publishing options and property promotion.
Save vs Submit
Completing a form
Email options.
Data Connections can be for
receiving
or
submitting
data.
Connections can be to SQL Server or Access databases,
Web Services, SharePoint List or Library or another
XML document.
Defining a connection creates another “
Data Source
”
in the InfoPath document.
InfoPath provides
form templates
to quickly configure
forms whose data structure is determined by an
external data source...
...from a database, a web service or an xml
document.
These templates „lock‟ your main data source schema
to be consistent with the data source you are
connection to.
Limited functionality for writing back to the data
source unless SQL Server or using code.
PLACE DEMO TITL HERE
Binding a drop down list row items
Using a Data Connection Template
Using The Submit Button
Public Sub exportXML()
Dim strStaffCode As String, filename As String, strPath As String
strPath = "C:\Users\pdbaker\Documents\SharePoint\LearningGateway2010\DemoDatabase2\" strStaffCode = "MCS"
filename = strStaffCode & ".xml"
Application.exportXML _
ObjectType:=acExportQuery, _ DataSource:="UCASComment", _
DataTarget:=strPath & "raw-" & filename, _
WhereCondition:="StaffCode='" & strStaffCode & "'" Transform _
sourceFile:=strPath & "raw-" & filename, _ stylesheetFile:=strPath & "InfoPath.xsl", _ resultFile:=strPath & filename
End Sub
Private Sub Transform(sourceFile, stylesheetFile, resultFile) ' courtesy of
http://www.oreillynet.com/xml/blog/2005/04/transforming_xml_in_microsoft.html
<xsl:template match="/"> <xsl:processing-instruction name="mso-infoPathSolution"> <xsl:text> solutionVersion="1.0.0.4" productVersion="12.0.0" PIVersion="1.0.0.0“ href="file:///C:\UCASComments.xsn" name="urn:schemas-microsoft-com:office:infopath:UCASComments:-myXSD-2010-07-09T19-58-45" </xsl:text> </xsl:processing-instruction> <xsl:processing-instruction name="mso-application"> <xsl:text> progid="InfoPath.Document" versionProgid="InfoPath.Document.2" </xsl:text> </xsl:processing-instruction> <xsl:apply-templates select="node()"/> </xsl:template>
Transform Stylesheets
Download an “identity transformation” and then modify the root template to include the InfoPath processing instructions.
XDocument xml = XDocument.Load(txtFile.Text); XNamespace ns =
"http://schemas.microsoft.com/office/infopath/2003/myXSD/2010-07-10T19:35:48";
var query =
(from p in xml.Elements(ns + "UCASComments").Elements(ns + "UCASComment")
select p.Element(ns + "StaffCode").Value).Distinct();
foreach (var record in query)
{
XDocument xmlOutput = XDocument.Load(txtFile.Text); var queryRemove =
(from p in xmlOutput.Elements(ns + "UCASComments").Elements(ns+"UCASComment")
where p.Element(ns+"StaffCode").Value != record
select p);
queryRemove.Remove();
xmlOutput.Save(txtOutput.Text + @"\" + record + @".xml"); }
Bound to web services
Our MIS
(WCBS PASS)
Code, form, email addresses
of student and teacher which
came from same web
service is separated into
fields.
[WebMethod]
public XmlDocument getFilteredStudents(string StartsWith) {
DBQuery dbq = new DBQuery();
QueryParamCollection qpColl = new QueryParamCollection(); string param = StartsWith.Trim();
param += param.EndsWith(@"%")?"":@"%"; qpColl.Add(new QueryParam("@StartsWith",param)); XmlDocument result = dbq.executeXMLDocument("zzGetStudentsFilteredXML",dbq.Connection,qpColl); return result; }
[WebMethod]
public XmlDocument getFilteredStudents(string StartsWith) {
DBQuery dbq = new DBQuery();
QueryParamCollection qpColl = new QueryParamCollection(); string param = StartsWith.Trim();
param += param.EndsWith(@"%")?"":@"%"; qpColl.Add(new QueryParam("@StartsWith",param)); XmlDocument result = dbq.executeXMLDocument("zzGetStudentsFilteredXML",dbq.Connection,qpColl); return result; }
CREATE PROCEDURE [dbo].[zzGetStudentsFilteredXML] @StartsWith VARCHAR(21) AS ( SELECT 1 as Tag, NULL as Parent, '1' as [outertag!1!id], null as [pupil!2!id], null as [pupil!2!name!element], null as [pupil!2!code!element], null as [pupil!2!form!element], UNION SELECT 2 as Tag, 1 as Parent, '1' as [outertag!1!id], PUPIL_ID AS [pupil!2!id],
SURNAME + ',' + PREFERRED_NAME + ' (' + [FORM] + ')' AS [pupil!2!name!element], CODE AS [pupil!2!code!element],
ISNULL([FORM], "NA") AS [pupil!2!form!element] FROM Curr_Pupils_Curr_Year
WHERE SUB_SCHOOL='UPPER' AND SURNAME LIKE @StartsWith )
ORDER BY [pupil!2!name!element]
Submit button which
submits first to PASS and
then also to a sharepoint
document library.
Our MIS
(WCBS PASS)
SP creates email
notifications and allows a
secretary to retrieve and
file any documentation
onto the pupil record.
[SUBMIT]
WORKFLOW
(SHAREPOINT DESIGNER)
Lookup from another SharePoint List
which stores extra staff that want to be notified on the form group level.
Case Study 5 : Perse Quiz Project
Images are extracted from the xml when it is submitted to the web service and replaced with the filename of the image. The XML is then just saved, ready to be displayed as a quiz using a stylesheet transform when the quiz is requested.
InfoPath does code
You can attach code to buttons, form events
and control events
Can be written in C#,VB, Jscript or VBScript
The interface is VSTA : Visual Studio tools for
applications.
You can control the user interface and also
control and requery the data connections using
the object model.
InfoPath does code
Example: Copy nodes directly from a data
connection to your own main data source.
InfoPath does code
public void btnLoad_Clicked(object sender, ClickedEventArgs e) {
// Create an XPathNavigator object to navigate the main data source XPathNavigator xpnMain = MainDataSource.CreateNavigator();
string strFilter = xpnMain.SelectSingleNode("/my:UCASComments/my:txtFilter", NamespaceManager).Value;
// Retrieve the connection object from the data connection
AdoQueryConnection myConn = (AdoQueryConnection)(DataSources["qryUCAS"].QueryConnection); myConn.Command =
@"select [StaffCode],[Department],[Pupil Name] as [PupilName],[Yeargroup] from [qryUCAS] as [qryUCAS]
where [StaffCode] like '" + strFilter + "%'"; myConn.Execute();
// Delete current ucas comments from the main data source XPathNavigator xpnOld;
do {
xpnOld = xpnMain.SelectSingleNode("/my:UCASComments/my:UCASComment", NamespaceManager); if(xpnOld!=null)
xpnOld.DeleteSelf(); } while (xpnOld!=null);
InfoPath does code
// Create an XPathNavigator object to navigate the data connection XPathNavigator xpnDConn = DataSources["qryUCAS"].CreateNavigator();
XPathNodeIterator xpnNewNodes = xpnDConn.Select("/dfs:myFields/dfs:dataFields/d:qryUCAS", NamespaceManager); XPathNavigator xpnUCASComments = xpnMain.SelectSingleNode("/my:UCASComments", NamespaceManager);
string nspace = xpnUCASComments.NamespaceURI; foreach(XPathNavigator xpnNew in xpnNewNodes) {
XmlWriter writer = xpnUCASComments.PrependChild(); writer.WriteStartElement("my", "UCASComment", nspace);
writer.WriteElementString("my", "StaffCode",nspace, xpnNew.SelectSingleNode("@StaffCode").Value); writer.WriteElementString("my", "Department", nspace, xpnNew.SelectSingleNode("@Department").Value); writer.WriteElementString("my", "PupilName", nspace, xpnNew.SelectSingleNode("@PupilName").Value); writer.WriteElementString("my", "Yeargroup", nspace, xpnNew.SelectSingleNode("@Yeargroup").Value); writer.WriteElementString("my", "Comment", nspace, "");
writer.WriteEndElement(); writer.Close();
} }