InfoPath - missing data connection files

 

Sometimes, your InfoPath doesn't show you all the data connection files available in your SharePoint data connections library:

image

In this screenshot, it is only showing 3. 
There is no way to navigate to see more.

 

Fix. 

Change the Item Limit in the default view for the Data Connection library in SharePoint.

image

 

Change that number.  The default is usually 30.  I had previously changed it down to 3 to take the earlier screenshot.  Let's bump it back to 300.

 

Now you can see all the data connections again.

image

Modifying CSS Styles based on InfoPath field without code

This is an article expanding on a comment I made previously on the Microsoft InfoPath forums.

http://social.msdn.microsoft.com/Forums/en-US/sharepointcustomizationprevious/thread/4a8dbae1-4641-4ee2-b034-3768ebda5a47

The Problem

How do we modify the margin of a column based on a field within InfoPath. 

 

Solution

Invoking dark magics of XSL (you have read the disclaimer).  This is totally unsupported, but fun.

  1. Create a new form, add a number field "n1".
  2. Put this field onto the design area within a section
  3. Create a rule on the section, "if n1 > 0", make the background red.
    (these steps are useful to set up the form to a stage where we can add additional rules).
  4. save your form as "MarginForm.xsn", we're about to do unsupported magic. 
  5. go to File | Publish | Export | Export Source Files - save the component files of your form into a blank folder, e.g. "C:\Temp\MarginForm\"
  6. close InfoPath designer, go to your folder, and look for the XSL file for your view, typically, it's <view name>.xsl.  For me, this is: C:\Temp\MarginForm\view1.xsl
  7. Open the xsl in a text editor - preferably one that understands XSL to give you syntax highlighting.
  8. Find our formatting rule, it looks like this:
    <xsl:attribute name="style">BORDER-BOTTOM: 0pt; BORDER-LEFT: 0pt; WIDTH: 100%; MARGIN-BOTTOM: 0px; BORDER-TOP: 0pt; BORDER-RIGHT: 0pt;<xsl:choose>
    <xsl:when test="../my:n1 &gt; 0">BACKGROUND-COLOR: #ff6600; caption: Rule 1;</xsl:when>
    </xsl:choose>
    </xsl:attribute>
  9. add additional formatting for margin-left, like this:
    <xsl:attribute name="style">BORDER-BOTTOM: 0pt; BORDER-LEFT: 0pt; WIDTH: 100%; MARGIN-BOTTOM: 0px; BORDER-TOP: 0pt; BORDER-RIGHT: 0pt;<xsl:choose>
    <xsl:when test="../my:n1 &gt; 0">BACKGROUND-COLOR: #ff6600; caption: Rule 1; MARGIN-LEFT: <xsl:value-of select="../my:n1"/>px;</xsl:when>
    </xsl:choose>
    </xsl:attribute>
  10. save your XSL, close it.  Open  the whole thing back in InfoPath designer from manifest.xsf
  11. test it and save it back into MarginForm.xsn file.
  12. Once you are comfortable and understand what's going on, clean up the rule in xsl (don't use the designer) and get rid of the rule for "red".

The Results

 

Download Files

 

A site maintenance notice.  I've removed all back references on the site - they were being spammed like crazy and I wasn't doing a good job of cleaning them up.  If you need a back reference, please leave a comment and I'll verify them.

InfoPath - reading template.xsd in code for type checking

InfoPath is the world's most advanced XML-based form system.  Each InfoPath document is a fully structured XML file, and the template contains the XSD schema definition for the XML file.  This includes a bunch of information such as min/max occurrences, as well as the type information for each of the elements.

Because the information for the element's type is stored separately in the xsd file, it isn't possible at runtime to workout what the type of each element is supposed to be. 
When we are given:

  • my:value1

If we can't read the template.xsd file, we don't know if that's a number, a string, a datetime nor do we know if the field is nillable.  Some fields in InfoPath, such as the boolean and the datetime fields, can't be blank.  They have to be set to nil.

 

Here's how you can read the template.xsd in code

An InfoPath Form

 

Here is an InfoPath form with a few fields

image

 

The XML File Connection

 

Add a XML File Data Connection to an existing file in the template, I use "template.xml"

image

Save the template, and now drop into the code behind.

 

Code

public void InternalStartup()
{
    EventManager.FormEvents.Loading += new LoadingEventHandler(FormEvents_Loading);
}

public void FormEvents_Loading(object sender, LoadingEventArgs e)
{
    FileQueryConnection file = this.DataConnections["template"] as FileQueryConnection;
    file.FileLocation = "template.xsd";
    file.Execute();
    XPathNavigator template = this.DataSources["template"].CreateNavigator();
    string notes = "";

    foreach (XPathNavigator nav in this.CreateNavigator().Select("//*", this.NamespaceManager))
    {
        string localname = nav.LocalName;

        XPathNavigator element = template.SelectSingleNode("//*[@name='" + localname + "']", template);
        if (element != null)
        {
            notes += string.Format("{0} is of type {1} {2}; ", localname, element.GetAttribute("type", ""), element.GetAttribute("nillable", ""));
        }
    }

    this.CreateNavigator().SelectSingleNode("/my:myFields/my:notes", this.NamespaceManager).SetValue(notes);
}

  • The interesting part is at the top, where we bait and switch the FileQueryConnection to read the template.xsd schema file instead.  Because it is a valid XML file, InfoPath will read it happily.
  • We can then map any field in the main datasource to the corresponding definition in the template, and pull out the additional metadata such as type or nillable.

 

Result

image

 

Download

Making InfoPath 2010 Preview/Debug work again

Quick blog.  How I fixed InfoPath 2010 Debug/Preview error, after installing Office 2013.

InfoPath cannot open the selected form because of an error in the form's code.
InfoPath will fail to load this form because Microsoft .NET Framework 3.5 is not installed or is installed incorrectly

Install .NET Framework 3.5

First, if you are on Windows 8, you do need to install the .NET Framework 3.5 feature.  Do this via Add Windows Feature control panel.

 

Reverse the .NET Assembly Binding Redirect Policies

Fix these two policies that was redirecting v14 references to v15.

  • C:\Windows\assembly\GAC_MSIL\Policy.14.0.Microsoft.Office.InfoPath.Client.Internal.Host\15.0.0.0__71e9bce111e9429c\ Policy.14.0.Microsoft.Office.InfoPath.Client.Internal.Host.config
  • C:\Windows\assembly\GAC_MSIL\Policy.14.0.Microsoft.Office.InfoPath\15.0.0.0__71e9bce111e9429c\ Policy.14.0.Microsoft.Office.InfoPath.config

If you just change it to bind to the original version 14:

  • <bindingRedirect oldVersion="14.0.0.0" newVersion="14.0.0.0"></bindingRedirect>

 

Missing IPDMCTRL

If you see complains about ipdmctrl, copy it from:

  • C:\Program Files (x86)\Microsoft Visual Studio 11.0\Visual Studio Tools for Office\PIA\Common\IPDMCTRL.dll to C:\Program Files\Microsoft Office\Office14\

You can find IPDMCTRL in any Visual Studio Tools for Office installation.  Your directory could be different.

 

Use the Fusion Log Viewer tool

I figured this out using the fuslogvw tool - which logs .NET assembly loading events, and so I could figure out what it was trying to load when debugging, and failing.

image

 

Pics or it didn't happen

image

 

Here is both VS2012 debugging an InfoPath 2013 form, at the same time as VSTO debugging a separate InfoPath 2010 form.

InfoPath - Form stuck on Installing, Upgrading or Deleting

When you publish an InfoPath Form through Central Administration, a few things happen:

  1. Central Administration creates a WSP package for this form.
  2. Central Administration creates timer jobs to deploy the package to each of the web applications that uses this form (defined by Activate to Site Collection, in Central Administration)
  3. Administration Service on each server then runs the timer job to deploy the form.
  4. The deployment job actually does a bunch of things:
    1. Creates a list of upgrade templates in \14\TEMPLATE\FEATURES\FT-01-72d7f7bc-0c6e-ba52-fa91-bb24c0014ed6
      Note, for some sites, this list is incredibly long, and can take a long time. I can't think of any good reason why we need all the versions, but may be this can potentially affect form upgrades.
    2. Creates a content type for the form
    3. Copy the form template to %site collection%/Form Templates/template.xsn
    4. (do other stuff)

Review this article from Microsoft: http://blogs.msdn.com/b/infopath/archive/2006/10/23/behind-the-scenes-of-administrator-approved-form-templates.aspx 

So when a form is stuck on "Installing" or "Upgrading"

 

  1. Check timer jobs. If there are jobs that can't start - they will wait
    1. Check all administration service are running on both servers
    2. Check timer service is running (timer service calls administration service to deploy)
  2. If your administration service is OFF, then you can try using the command line to execute those timer jobs
    1. stsadm -o execadmsvcjobs
    2. The benefit is if there's exceptions thrown here you'd see it in the console
    3. Do this on all SharePoint servers. If the administration service is running, then this stsadm command won't do anything.
  3. If your job is missing, you can check in Solution Management /_admin/Solutions.aspx
    1. Go to Solution Management under Central Administration /_admin/Solutions.aspx
    2. Find the farm solutions that for the form. The name would be form-formname.wsp.
    3. If the solution isn't deployed, you can select deploy - global
    4. If your admin service isn't running, you'll get a warning saying that jobs are scheduled but no admin service means they won't run.
    5. Use stsadm -o execadmsvcjobs
  4. If nothing else works, or if we want to do a complete removal.
    1. In form templates, select the form template, and hit Remove.

Form is stuck on "Deleting"

  1. Go to Solution Management under Central Administration /_admin/Solutions.aspx
  2. Find the farm solutions that for the form. The name would be form-formname.wsp.
  3. If the status is Deployed, then retraction hasn't started.
  4. Click the package and select Retract Solution.
  5. If your admin service isn't running, you'll get a warning saying that job is scheduled but no admin service means they won't run.
  6. In command line, stsadm -o execadmsvcjobs, on both servers.
    C:\ > stsadm -o execadmsvcjobs
    Executing job-application-server-admin-service.
    Executing job-password-management.
    Executing solution-deployment-form-tradepackageform.wsp-0.
    Operation completed successfully.
  7. You'll see this back on solutions.
  8. Name:    form-packageform.wsp
    Type:    Core Solution
    Contains Web Application Resource:    No
    Contains Global Assembly:    No
    Contains Code Access Security Policy:    No
    Deployment Server Type:    Front-end Web server
    Deployment Status:    Deployed
    Deployed To:    Globally deployed.
    Last Operation Result:    The solution was successfully retracted.
    Last Operation Details:   
    SRV02 : The solution was successfully retracted.
    SRV03 : The solution was successfully retracted.
    Last Operation Time:    1/8/2013 11:01 AM

  9. You can then remove the solution package.
  10. If you go back to Form Template management, the form will be removed from the list, and you can re-upload as usual.