Thursday 7 August 2008

XmlFormView used in a Sharepoint Environment Error

When following the tutorial on deploying an infopath form in asp.net web page into sharepoint you might get the strangest of errors saying

"The type 'Microsoft.Office.InfoPath.XmlForm' is defined in an assembly that is not referenced."

If you get this ensure that the web.config file for the SharePoint contains the Infopath Assemblies

-----web.config ----








---web.config----

This is the url that walks thru the hosting of the infopath forms in a custom page. Please be aware that the tutorial only caters for situations where you are hosting the .net page in the root site collection.

http://msdn.microsoft.com/en-us/library/aa701078.aspx#infopathxmlformviewcontrolcustomwebpage_deployingnonroot

Using query string with InfoPath forms

Sometimes it is necessary to accept query string for browser enabled info path forms. This can be done by hosting the Infopath form in a asp.net page and hosting that page within Sharepoint using the XmlFormView class.

This technical guide explains the process

http://msdn.microsoft.com/en-us/aa701078.aspx

The code behind for the asp.net page will contain a method like the one shown below..

protected void XmlFormView1_Initialize(object sender, InitializeEventArgs e)
{
string positionAppliedFor = Request.QueryString["Position"];
string jobID = Request.QueryString["JobID"];
string appURL = Request.QueryString["AppURL"];

if (!string.IsNullOrEmpty(positionAppliedFor) && (!string.IsNullOrEmpty(jobID)))
{
// Create an XPathNavigator positioned at the root of
// the form's main data source.
XPathNavigator xNavMain = XmlFormView1.XmlForm.MainDataSource.CreateNavigator();
// Create an XmlNamespaceManager and add the "my" namespace
// alias from the form's main data source.
XmlNamespaceManager xNameSpace = new XmlNamespaceManager(new NameTable());
xNameSpace.AddNamespace("my", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2008-07-08T12:49:29");
// Create an XPathNavigator positioned on the form's field2.
XPathNavigator fTextBoxPosition = xNavMain.SelectSingleNode(
"/my:myFields/my:gpRecommendation/my:txtPositionAppliedFor", xNameSpace);
// Set the form's job Position Value to the value passed in the query strings
fTextBoxPosition.SetValue(positionAppliedFor);

XPathNavigator fTextBoxJobID = xNavMain.SelectSingleNode(
"/my:myFields/my:gpRecommendation/my:txtJobID", xNameSpace);
fTextBoxJobID.SetValue(jobID);

if (!string.IsNullOrEmpty(appURL))
{
XPathNavigator fTextBoxAppURL = xNavMain.SelectSingleNode(
"/my:myFields/my:gpRecommendation/my:txtAppURL", xNameSpace);
fTextBoxAppURL.SetValue(appURL);
}
}
}

Installing SharePoint on a simple farm

Very comprehensive guide on installing SharePoint on a simple farm

http://technet.microsoft.com/en-us/library/cc262243.aspx

Validating Currency fields regular expression

Expression: ^\d{0,2}($|\.\d{0,2}$)
Example of valid values:
20.09
1.99
1.2
3
.5

Example of invalid values:
120.09
1.991
x