Archive for the 'InfoPath' Category

10
Jul
13

InfoPath 2010 Form: Redirect to your source Page once form has been closed

I’ve noticed that this topic has been asked about by many people and I thought I’d offer up what I did to eliminate this problem.

For those not familiar with this issue, when you create an InfoPath form and create Submit and Cancel buttons, it is likely you want the Cancel operation to redirect or return you to your originating page.  Some folks want to display a "Thank you" page after a submit and then return to their originating page.  While you can do this with scripting, such as JavaScript found here, I think I have a simpler method that doesn’t require you write any custom JavaScript (although it does use a built-in SharePoint JavaScript function).

The trick I used was to open the form in a dialog.  That way, when you click Cancel, the dialog is dismissed and you remain on the same page from which you opened the dialog.

Here’s some example html.

<a href="javascript:OpenPopUpPage(‘uploadfile.aspx?ProjectID={@PMO_x0020_Project_x0020_ID}’, RefreshPage);">

In this case, uploadfile.aspx is located in the pages library and is a custom page with an InfoPath form web part on it.  The custom page also has a URL filter on it that is connected to the form.  The parameter, ProjectID, is a URL parameter that is passed to the form through a web part connection.

Here is an image that has the above hyperlink (Upload File) anchored to it.

image

This opens the page below in a dialog.  Notice how the Project ID is defaulted on the form using a URL parameter that is sent to the form web part using a web part connection.

image

When Cancel is clicked, the dialog is dismissed and we’re right back where we started.

For the "Thank you" page, I’d recommend creating another view in InfoPath and simply switching views after the submit with your "thank you" text and provide an OK button to close the form.

25
Nov
12

Unsupported Expression in InfoPath 2010

 

This is a weird one.

Situation:

Going back to a SharePoint 2007 site formerly published with InfoPath 2007.  Downloaded the form template and made some changes.  When I went to re-publish I encountered an “unsupported expression” error.

image

The actual long message was as follows.

The following expression could not be parsed because of a syntax error or because it uses an undefined namespace prefix or unsupported function:  pc:DisplayName

image

This appeared to have been coming from one of the people pickers (circa 2007 variety) but copying the Xpath on each of them yielded no easily identifiable pc:DisplayName.

/my:myFields/my:EmployeeManager/my:Person/my:DisplayName

/my:myFields/my:EmployeeGroup/my:TerminatingEmployee/my:Person/my:DisplayName

I went back to the original template with no changes and it didn’t throw the same error during publishing.

I changed the Form type from Web Browser Form (InfoPath 2007) to InfoPath 2007 Filler Form and attempted publishing.  The error went away.

image

So, I changed it back to Web Browser Form (InfoPath 2007) again…the way it originally was.  The error stayed away and I published the form. 

However, after publishing, the error came back.  Sad smile  So I decided to look “under the covers.”

I saved the XSN as source files and looked within all the files.  I was able to find where the pc: schema infiltrated my form template.  Within view1.xsl I found the offending pc:DisplayName, and all the other related pc: references. 

image

I’m not sure how this made its way into the form template, as I never specifically made this change, nor do I know how one would force this. 

</xsl:if>

                                        <param NAME="ButtonFont" VALUE="Verdana,12,0,400,0,0,0"/>

                                        <param NAME="ButtonText" VALUE=""/>

                                        <param NAME="DisplayNameXPath" VALUE="pc:DisplayName"/>

                                        <param NAME="ObjectIdXPath" VALUE="pc:AccountId"/>

                                        <param NAME="ObjectTypeXPath" VALUE="pc:AccountType"/>

                                        <param NAME="SiteUrlXPath" VALUE="/Context/@siteUrl"/>

                                        <param NAME="SiteUrlDataSource" VALUE="Context"/>

                                        <param NAME="NewNodeTemplate" VALUE="&lt;pc:Person xmlns:pc=&quot;http://schemas.microsoft.com/office/infopath/2007/PartnerControls&quot;&gt;
    &lt;pc:DisplayName&gt;&lt;/pc:DisplayName&gt;
    &lt;pc:AccountId&gt;&lt;/pc:AccountId&gt;
    &lt;pc:AccountType&gt;&lt;/pc:AccountType&gt;
&lt;/pc:Person&gt;"/>

                                        <param NAME="BackgroundColor" VALUE="2147483653"/>

                                        <param NAME="MaxLines" VALUE="4"/>

                                        <param NAME="Direction" VALUE="0"/>

I did a simple “find and replace” on all the pc: occurrences with my: and saved and tested my work.  All appears to be okay.

Sure would be nice to know how this happens!

21
Nov
12

InfoPath Blog Silent?

Is it just me, or has anyone noticed the InfoPath team blog at http://blogs.msdn.com/b/infopath/ has been silent for the last year and a half?  Did they move it somewhere else when I wasn’t looking?  Or, did I finally look up for a minute, only to find the world has passed me by…again?

02
Oct
12

Launch form in a dialog doesn’t work correctly when displaying a list in datasheet view

This was driving me nuts.  I had a custom list in SharePoint 2010 and I wanted the new item form to NOT open in a dialog.  No matter what I did, it kept opening in a dialog.

image

Then I stumbled upon what was causing my issue!  Whenever the list was displayed in a datasheet view (which was my default), the new item form would always display in a modal dialog.

List displayed in datasheet view.

image

 

 

 

 

 

 

 

 

 

 

Create a new entry…

 

image

 

…and modal dialog is displayed (notice no master page "chrome”).

 

image

 

Change to standard view…

 

image

 

…and the form is opened up in single page mode (notice master page “chrome”).

 

image

What’s up with that?

An interesting thing to note is this problem also exists with Calendar lists.  If you display a calendar list in anything other than a normal list view, the “Launch forms in a dialog” will not be respected when set to “No.” 

Again, if we set “Launch forms in a dialog” to “no” and view the calendar in “Calendar” view…

 

image

 

…and attempt to create a new event while in this view…

 

image

 

…the form opens in a dialog.

 

image

 

If we change to the “All Events” view and attempt the same thing…

 

image

 

The form is opened in a new page (no dialog).

 

image

 

Perhaps this is the designed behavior, but if it is, I would recommend renaming the option to “Launch forms in a dialog when showing items in standard view.”

The description of the option would lead one to believe there might be times when a dialog would not be displayed when you would expect it to be displayed…not the other way around.

 

image

 

I guess I shouldn’t be disappointed when I get “free” dialog forms.

 

Keywords:

Launch form in a dialog broken

Launch form in a dialog doesn’t work for custom list

List view affects dialog form

19
Dec
10

Removing the view selector from a Sharepoint 2010 infopath form

If you have created custom InfoPath forms for a list in SharePoint 2010 and you have custom views for each of the New, Edit and View forms, you might find the InfoPath view selector showing up when you don’t want it to.  This could allow users to change to the Edit view on your New item form, for example.

image

To fix this, you can select the View Properties from the Page Design menu in InfoPath and uncheck the “Show on the View menu when filling out the form” option.

image

 

image

If all of your views have this unchecked, then the view selector will not appear on the SharePoint InfoPath form.

31
Mar
10

All Toolbars Missing from InfoPath 2007

An advanced InfoPath client of mine was working in InfoPath 2007 the other day and suddenly, all his toolbars disappeared.  Even the toolbar with the File menu on it was gone.  The only thing that showed up in design mode was the task pane on the right.

After talking with him, he told me he had repaired and uninstalled/reinstalled InfoPath but the problem remained.  After searching around the registry and thinking that I might have found something at HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Common\Toolbars\Settings\Microsoft Office InfoPath, through trial and error we found that that key didn’t have any effect on the missing toolbar problem. 

I had him log on as another user and start up InfoPath and the toolbars were there, so it certainly appeared to be a user settings issue.  I found this article about Excel 2000 and decided to poke around and see if InfoPath had the same type of toolbar settings.  Sure enough, in C:\Documents and Settings\[UserName]\Application Data\Microsoft\InfoPath there is an infopath.tbs file.  After renaming this file and restarting InfoPath the toolbars reappeared.

Don’t know what happened to corrupt this file, but now we know how to fix it.

19
Feb
10

InfoPath Code to Hide All Toolbars When Filling Out a Form

There are probably several ways to do this, but this seemed pretty straightforward to me.  The code loops through the CommandBars collection that is part of Microsoft.Office.Core and sets the Enabled property to false.  If you want, you can selectively inspect each toolbar in the collection and enable/disable specific ones.

You can use the Context Changed Event to set a spiffy title for your form.  Be aware that, if the Context Changed Event is grayed out, you need to change the form’s browser compatibility options so it is not able to be opened in InfoPath Forms Services.

image

Uncheck the box “Design a form template that can be opened in a browser or InfoPath.”

image

Since we are using code, you’ll have to fully trust the form and sign it.

image

We’re using C# in this example, so set the form template code language to C#.

image

Add a reference to Microsoft.Office.Core by browsing to MSO.DLL in your Microsoft Shared folder.  You can see it here in my list of recent references.

image

image

Now you should be able to add the USING statement for Microsoft.Office.Core.

 

using Microsoft.Office.InfoPath;
using Microsoft.Office.Core; // Required for Commandbars
using System;
using System.Xml;
using System.Xml.XPath;
using System.Windows.Forms;
using mshtml;

namespace Test_Form
{
    public partial class FormCode
    {
        #region EventHandlers
        public void InternalStartup()
        {
            EventManager.FormEvents.Loading += new LoadingEventHandler(FormEvents_Loading);
            EventManager.FormEvents.ContextChanged += new ContextChangedEventHandler(FormEvents_ContextChanged);           
        }
        #endregion

        #region Toolbars

        public void FormEvents_ContextChanged(object sender, ContextChangedEventArgs e)
        {
            if (this.New)
            {
                this.Application.ActiveWindow.Caption = “Fill out my form!”;
            }
        }

        public void FormEvents_Loading(object sender, LoadingEventArgs e)
        {
            HideAllToolbars();
        }

        void HideAllToolbars()
        {
            // The main toolbar with the file menu will be hidden (msoBarTypeMenuBar)
            // along with all the other toolbars (msoBarTypeNormal)
            // if HideToolbarsFlag is true in the datasource
            /* List of enumerated menu bars
                Menu Bar msoBarTypeMenuBar 1
                Standard msoBarTypeNormal 2
                Print Preview
                Formatting
                Tables
                Ink
                Task Pane
                Property Editor
                Office Clipboard
                XML Source
                Research
                XML Document
                Signatures
                Document Actions
                Clip Art
                Selection and Visibility
                Document Management
                Document Updates
                Mail Merge Panes
                Fax Service
                Meeting Workspace
                Attachment Options
                Clipboard
                Envelope
                System
                Online Meeting
             * */
            XPathNavigator root = MainDataSource.CreateNavigator();
            string hideToolbarsFlag = root.SelectSingleNode(“//my:HideToolbarsFlag”, NamespaceManager).ToString();
            bool flag;
            if (hideToolbarsFlag.ToLower() == “true”)
            {
                flag = true;
            }
            else
            {
                flag = false;
            }

            CommandBars myCommandBars = this.Application.ActiveWindow.CommandBars as CommandBars;
            CommandBar myCommandBar = (this.Application.ActiveWindow.CommandBars as CommandBars).ActiveMenuBar;
            foreach (CommandBar item in myCommandBars)
            {
                //MessageBox.Show(item.Name.ToString() + ” ” + item.Type.ToString() + ” ” + item.Index.ToString());
                if (flag == true && (item.Type == MsoBarType.msoBarTypeMenuBar || item.Type == MsoBarType.msoBarTypeNormal))
                {
                    item.Enabled = false;
                }
            }
        }
        #endregion

    }
}

In order to control whether the toolbars are displayed or not, a field is added to the data source.  Add the element, HideToolbarsFlag, that will control whether or not to hide the toolbars.

image

image

This bit of code retrieves it’s value.  If you set the default value to true, it hides the toolbars; anything else, it doesn’t.

string hideToolbarsFlag = root.SelectSingleNode(“//my:HideToolbarsFlag”, NamespaceManager).ToString();

And now preview your form.

image

04
Feb
10

Establishing a Reference to InfoPath SemiTrust and InfoPath Xml Interop Libraries in VSTA

If you are attempting to use the namespaces

using Microsoft.Office.Core;
using Microsoft.Office.Interop.InfoPath.SemiTrust;
using Microsoft.Office.Interop.InfoPath.Xml;

in your VSTA project, you’ll find that you need to include some references. 

In order to get the Interop references, you may need to download and install Office 2003/2007 Primary Interop Assemblies (PIA) redistributable package.  You also want to make sure you have the .NET Programmability Support and VSTA installed for InfoPath.  You can use Add/Remove Programs in Office 2007 to insure you have .NET Programmability Support/Visual Studio Tools for Applications installed.

Add/Remove Programs showing interop assembly entries

image

Add/Remove features on Office 2007 showing InfoPath section

image

Now you need to add the references.  You’ll find the DLLs you need to reference in \Program Files\Microsoft Office\Office12.  Microsoft.Office.Interop.InfoPath.SemiTrust.dll and Microsoft.Office.Interop.InfoPath.Xml.dll.

.image

You can use the browse feature when adding the reference to find the DLLs.

image

The reference to Microsoft.Office.Core is from either the Microsoft Office 11.0 Object Library (Office 2003) or the Microsoft Office 12.0 Object Library (Office 2007).

image

 Happy automating!

01
Feb
10

Capturing Multiple Signatures in an InfoPath 2007 Form Using a Topaz Signature Pad

We (Richard Wixom and Russell Wright – RW2) have done some work using a Topaz signature pad to capture an actual image of a signature in an InfoPath 2007 form and store it in the form XML as a base64 encoded image.  We blogged about it here.  Well, we’ve recently improved upon the process to easily allow multiple signatures to be added to a form template.

The new process involves much of the existing code, but encapsulates each signature block as a template part.  Adding a template part and tying it to the code is a simple process.  In our solution, the template part is added and then the SIGN and DONE buttons are renamed so they reference the same C# code in the form template.  So, within a form template, the SIGN and DONE buttons are the same buttons referenced in each of the signature sections.  The solution is pretty slick because it looks at the outer XML to find all the controls that are related to the section associated with a signature and doesn’t require the designer of the form to muck with the code.  They just add the template part, rename the buttons, and they are on their way.  Cool!  Chalk up another one for SharePoint Rx.

clip_image002

11
Sep
09

Using Topaz Signature Pads to Capture Signatures for InfoPath 2007 Forms

This is a great solution created by Richard Wixom, whom I’ve worked with over the years.  Richard is the president and owner of DNSalePrice.com.  He spends a lot of his time buried in algorithms deciphering the goings on in the domain name industry and creating huge databases with information about domain names.  We collaboratively worked on this solution and thought it was an interesting exercise that others might appreciate.

TOPAZ Signature Pads can be enabled for InfoPath 2007 with the signature image then stored and embedded within the InfoPath form. The following approach uses C#/.Net managed code with the code and appropriate DLL’s embedded within published InfoPath forms. Standard InfoPath features such as email distribution, SharePoint storage, etc. are available for InfoPath client. Web-enabled InfoPath forms are not supported.

Prerequisites for enabling TOPAZ Signature Pads with InfoPath 2007:

1. TOPAZ signature pad hardware and software installed.

2. Security level for InfoPath form set to Full Trust and signed.

3. Programming language for InfoPath form set to “C#”

4. Compatibility for InfoPath form and “Design form template that can be opened in browser” is not set.

5. Local access to the C# SigPlusNET assembly. This can be found in the Topaz’s “SigPlusNETDemoCSharp” download that is available here.

Setup requires three steps:

1. Adding the required controls to InfoPath form

2. Adding DLL reference to code

3. Adding required code

Estimated time to complete should be under five minutes.

Add Required Controls

In “Design” mode, create a new InfoPath form and verify/set settings as stated in “Prerequisites.” Add two Buttons, a Text Box and a Picture control to the form. Use a layout similar to the following:

clip_image002

Set the control properties on the first button (Label and ID) as shown below. Both C# and XML are case-sensitive languages so be sure to use the same letter case as shown.

clip_image004

Set the control properties for the second button as shown below:clip_image006

For the Text Box properties, under Data tab, set Field name as shown below:

clip_image008

For the Text Box properties, Display tab, check “Read-only” as shown below:

clip_image010

For the Text Box properties, Size tab, set size values as shown below:

clip_image012

For the Picture properties, under the Data tab, enter Field name as shown below and uncheck the box to “Allow the user to browse, delete, and replace pictures.”

clip_image014

Under Tools/Programming, open Microsoft Visual Studio Tools for Applications. In the Project Explorer (see tabs on right), right-click on “Reference”, select “Add Reference” and add the following two references:

1. Under the .Net tab, locate and add “System.Drawing”.

2. Under the Browse tab, navigate the full path to SigPlusNETDemoCSharp (see Prerequisites) and add “SigPlus.dll”.

Project Explorer should now look like the following (see highlighted reference):clip_image016

Now cut and paste the following replacement code over the default code — EXCEPT you will need to preserve the default namespace that is provided. The following is an example of the default namespace that you’ll need to preserve when pasting the replacement code.

clip_image018

Replacement code:

using Microsoft.Office.InfoPath;
using System;
using System.Windows.Forms;
using System.Xml;
using System.Xml.XPath;
using mshtml;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
namespace _0900_A_with_Signature ç [retain the default value here]
{
public partial class FormCode
{
internal Topaz.SigPlusNET SigPlus = new Topaz.SigPlusNET();
// NOTE: The following procedure is required by Microsoft Office InfoPath.
// It can be modified using Microsoft Office InfoPath.
public void InternalStartup()
{
((ButtonEvent)EventManager.ControlEvents["Button_Sign"]).Clicked += new ClickedEventHandler(Button_Sign_Clicked);
((ButtonEvent)EventManager.ControlEvents["Button_Done"]).Clicked += new ClickedEventHandler(Button_Done_Clicked);
}
public void Button_Sign_Clicked(object sender, ClickedEventArgs e)
{
SetSignatureImage(String.Empty);
SetTopazMessage("Sign on signature pad and then click \"Done\".");
SigPlus.SetTabletState(1); //tablet on
SigPlus.ClearTablet();
}
public void Button_Done_Clicked(object sender, ClickedEventArgs e)
{
SigPlus.SetTabletState(0); //tablet off
SigPlus.SetImageXSize(400);
SigPlus.SetImageYSize(100);
SigPlus.SetImagePenWidth(11);
SigPlus.SetJustifyMode(5);
Image sigImage = SigPlus.GetSigImage();
String sigBase64 = ImageToBase64(sigImage, ImageFormat.Jpeg);
//verify signature entered and read
if (sigBase64.Length > 2000)
{
SetSignatureImage(sigBase64);
SetTopazMessage(string.Empty);
}
else { SetTopazMessage("Signature not recoginized. Please verify signature pad, then click \"Sign\" button and follow instructions."); }
}
public void SetTopazMessage(string message)
{
string XpathForTopazMessage = "/my:Fields/my:TopazMessage";
XPathNavigator messageField = this.MainDataSource.CreateNavigator().SelectSingleNode(XpathForTopazMessage, NamespaceManager);
messageField.SetValue(message);
}
public void SetSignatureImage(string base64Image)
{
string XpathForSignatureImage = "/my:Fields/my:SignatureImage";
XPathNavigator imageField = this.MainDataSource.CreateNavigator().SelectSingleNode(XpathForSignatureImage, NamespaceManager);
DeleteNil(imageField); //remove xsi:nil attribute
imageField.SetValue(base64Image);
}
public string ImageToBase64(Image image, ImageFormat format)
{
using (MemoryStream ms = new MemoryStream())
{
// Convert Image to byte[]
image.Save(ms, format);
byte[] imageBytes = ms.ToArray();
// Convert byte[] to Base64 String
string base64String = Convert.ToBase64String(imageBytes);
return base64String;
}
}
public void DeleteNil(XPathNavigator node)

{

if (node.MoveToAttribute("nil","http://www.w3.org/2001/XMLSchema-instance&quot;))
{
node.DeleteSelf();
}
}
}
}

Click on “Build” and verify that your template builds without programming errors. If you encounter any errors, correct as required. The most common error will be incorrect entry of control ids as noted above.

Save your source files, close Visual Studio for Applications, add required content and controls to your InfoPath form and publish.




Asif Rehmani’s SharePoint Videos

SharePoint-Videos

Click to access a wealth of SharePoint videos

SharePoint Rx

SharePoint Rx Home

Categories

Posts by Date

October 2020
M T W T F S S
 1234
567891011
12131415161718
19202122232425
262728293031  
Support Wikipedia