Posts Tagged ‘infopath’

Infopath Namespace manager creation code

February 18, 2014 Leave a comment

I have had to create some code this week that reads the xml created by InfoPath. I then found that if you try and xpath on something you get a null return until the namespace manager has all of the correct entries. In the past I have created these manually but after a bit of google fo I have come up with the below piece of code. It takes an XMLDocument that you have created based on the form file (or any XML document really) and returns you a newly created namespace manager that can be used along side you xpath queries to get the data you want.



public static XmlNamespaceManager GetNameSpaceManager(XmlDocument xmlDoc)
XmlNamespaceManager ns = new XmlNamespaceManager(xmlDoc.NameTable);
foreach (XmlAttribute att in xmlDoc.DocumentElement.Attributes)
if (att.Prefix == "xmlns")
ns.AddNamespace(att.LocalName, att.Value);
return ns;

.csharpcode, .csharpcode pre
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
background-color: #f4f4f4;
width: 100%;
margin: 0em;
.csharpcode .lnum { color: #606060; }

Categories: work Tags:

How to hide fields for new items using InfoPath

January 23, 2014 Leave a comment


A client had a fairly simple request to hide some fields when a new SharePoint list item is created but have these fields shown once the item has been created and people edit the form. The short version is that you can use the inbuilt ID field to see if an item is new or not. If the ID field is blank then it is a new form.


Here are the steps required so that you can hide fields when an item is being created. Make sure not to hide any required fields or the form cannot be saved.

These steps require InfoPath 2010 client to be installed

1. Navigate to the list

a. I have created a very simple list where users will ask a question. The goal is only to allow users to fill out the title field when an item is created


2. From the ribbon select the Customize Form option

a. clip_image001

b. If this option is missing then following feature is probably not activated

c. clip_image002

3. A form will now have opened in InfoPath 2010

a. clip_image003

4. Each field can be hidden manually or all of the fields you want to hide can be added to a new section and then you just hide the section.

a. Select the Section control and add to the bottom of the form

b. Copy or cut the required rows or fields from the table into the section. It will look similar to the following screen shot

c. clip_image004

5. Now we need to add a rule to the section to hide it.

a. Select the Manage Rules option from the ribbon

b. clip_image005

c. Highlight the section (Click on it)

d. clip_image006

e. From the Rules menu on the left hand side select New and then Formatting.

i. Change the name to be Hide Section

ii. Click on the None under condition and change it to the following

iii. clip_image007

iv. Now select the Hide this control option

v. The whole rule should look like

vi. clip_image008

6. Using the publish button in the very top left of InfoPath publish you changes back to the server. clip_image009

a. You should receive an OK message once this is complete

7. Now navigate to the list and test to see if it has worked

Here is the new form


This is what the form looks like when an existing item is edited


This is just a very basic example. The overall style of the form can be changed using the formatting option within InfoPath.

Rule can also be applied directly to some fields so they do not have to be moved into a section if you do not want to. The attachment control must be added to a section as rules cannot be applied against this control directly.

Categories: work Tags:

Recursive rules in InfoPath–How to prevent

September 24, 2013 Leave a comment


A while ago I had a scenario in an InfoPath form where the user could either enter an amount or a percentage value. This value would then get added to a total already in the form. The requirement is that the user enters either value and the form then calculates the other one.

So if I enter a number then the percentage gets calculated. If I entered the percentage then the number value gets calculated.

So I quickly setup some rules so that when the value changed the percentage or the whole numbers gets calculated and updates the relevant field. This creates a loop of continually updated fields.


I had hoped that some clever InfoPath “stuff” would just make this work and I wouldn’t have to worry about the issue. This didn’t work and caused the form to fail or the fields would not update correctly.


The solution to this problem is that you need a third field to control the updates. Mine is called “Calculating” and is a simple Boolean field.


Now in the rules for Field1 (number) and Field2 (percentage) the first thing to do is to check that calculating = 0 then set calculating = 1 and then set your field. At the end set Calculating back to 0.


This is just a very simple implementation of a lock but it stops the InfoPath rules going crazy.



Pictures explain everything

Categories: work Tags: ,

Infopath “The following form template cannot be upgraded because it is not currently uploaded on this farm” #sp2010

August 1, 2012 2 comments

So what i was trying to do is upload a new form template to a clients QA system. Something that has been done tens of time since the system went live. But today I get.



Now i have never seen this message before so i instantly start googling to try and save the day.

I have to say not a lot of stuff around this error is available but there are a couple of MSDN forum posts that got me in the right direction.


The SharePoint farm in question has recently had some more servers added to the farm and what i suspect has happened is that the form files have not correctly deployed to the new servers. But to prove this i need the feature GUID that is created when you first upload a InfoPath form.


I found the quickest way to get this is to navigate to the site collection the form exists on. Go to Site settings and under Site collection Administrators select the Site Collection Features in the list you will see a feature that maps to the name of the XSN file.

Click on the Deactivate button (don’t worry there is a confirmation step). Now in the query string the feature GUID is shown. Copy this as you will need it later. You don’t need to deactivate the solution so can close the page if you wish.


I was then able to see, under Solution Management within central admin the WSP called the same GUID. Clicking on the WSP showed me that the wsp had not been deployed to all the servers in the farm. For some reason all of the other WSP in the list had all been deployed. I guess i was just lucky that this was the only one.


Now to fix the issue you need to run an STSADM command


stsadm -o uninstallfeature –id <the feature GUID you got from the query string> –force


This will remove the feature and i guess some other magic that fixes stuff.

Now the form can be upgraded without an error. Once the form has upgraded the feature is reactivated automatically (did for me anyway)

And YAY it all works again. 5 minutes job only took an hour


Hope this helps someone

Categories: CPS, work Tags: , ,

Infopath DB – query a form library like it is a list

September 21, 2011 2 comments

This looks very interesting and could overcome the limitation of promoted fields


Categories: work Tags: , ,

Security Validation Issue – Form Services issue with SP1+June 2011 CU (Release 2)

July 20, 2011 Leave a comment

I am experiencing a problem in Infopath 2010 after upgrading to SP1 and June CU.

A nice detailed explanation of the issue is posted here

Categories: work Tags: , , ,

Migration InfoPath 2010 Browser form from Dev to QA. Production or Live Systems

Thought I’d share these steps with you as I have just had to do them. As with all MS stuff there is a few way floating around the web on the best approach to this. The method I have chosen best replicates the process established for InfoPath 2007. A bit long winded but it doesn’t take that long to do.

  1. Right click on your InfoPath XSN form and select design (the normal way you open your forms when making changes)
  2. Go to File->Publish and select “Export Source Files”
    1. Create a folder to contain the exported files and select OK. The files will now be exported
    2. Close InfoPath and DO NOT SAVE
    3. Go to the folder with the exported files.
    4. Open the Manifest.xsf in your favourite editor (Visual Studio)
      1. Use find and Replace to replace server references to reflect the new system. Don’t forget any database references
      2. Save and close the files once finished
      3. Right-click on the Manifest.xsf and select design. This will open as normal.
      4. Go to File->Publish and Select “Publish form to SharePoint Library”
        1. Follow wizard as normal changing the publish XSN location if needed
        2. Close the form
        3. Upload new template to server.
        4. At this point I would delete the folder containing the exported files so that there is only 1 copy of the form template.
Categories: work Tags: , ,