Code Snipets

Infopath Only Date alloweded error while updating date filed using code

Posted in Infopath by mauliksoni on September 3, 2010

When you update infopath form xml using code, you might get an error “only date alloweded” for date fields. Something like this-

infopath form - only date allowded error

infopath form - only date allowded error

The problem is you need to convert the date string into xml schema specific format.


strNow = XmlConvert.ToString(DateTime.Now, "yyyy-MM-ddTHH:mm:ss");
PurchaseDateTimeNode.SetValue(strNow);

OR


PurchaseDateTimeNode.SetValue(XmlConvert.ToString(System.DateTime.Now));

NOTE: If your infopath form field is Nullable ( xsi:nil=”true” ) then you will need following additional code to update null date field to not null.

private static void RemoveXsiNil(XmlDocument originalDoc, XmlNamespaceManager nsmgr, string key)
{
try
{
//remove xsi:nil="true" attribute because this field will now has a value
XmlNode xn = originalDoc.LastChild.SelectSingleNode("my:" + key, nsmgr);
XmlAttribute xa = xn.Attributes["xsi:nil"];
originalDoc.LastChild.SelectSingleNode("my:" + key, nsmgr).Attributes.Remove(xa);
}
catch(Exception ex)
{
throw ex;
}
}

checklist for enabling browser forms with Forms Services and SharePoint 2007

Posted in Infopath, Sharepoint by mauliksoni on September 3, 2010

This is a checklist to follow if you are having problems with publishing InfoPath 2007 browser-enabled forms to Microsoft Office SharePoint Server 2007. A typical error message you receive in this case is

This form template is browser-compatible, but it cannot be browser-enabled on the selected site

… with an ugly yellow color. Here’s what to check before you’re going crazy:

  1. Install Microsoft Office Forms Server 2007 (independent product) on the SharePoint box if the Office server suite you use is lower than Enterprise (or if you are using Windows SharePoint Services 3.0). The Forms Services support is included in the Enterprise Office Server suite.
  2. After installed Forms Server, you’ll have a InfoPath Forms Services section at the Application Management page. To go here, click on Start -> Administrative Tools -> SharePoint 3.0 Central Administration and choose the Application Management tab on the top of the page. Click on Configure InfoPath Forms Services in the InfoPath Forms Services section and check both “Allow users to browser-enable form templates” and “Render form templates that are browser-enabled by users” checkboxes, then OK this page
  3. Open your SharePoint site, click on Site Actions -> Site Settings, select Site collection features under Site Collection Administration and activate InfoPath Forms Services support
  4. Start designing your form with the InfoPath 2007 client. In InfoPath, click on Tools/Form Options, select the Compatibility category and check the “Design a form template that can be opened in a browser or InfoPath“, then click OK. In the case if you miss this one and your form is browser-compatible, you get a warning message while publishing your form saying that “The server is running InfoPath Forms Services, but the compatibility settings for this form template is InfoPath only“.
  5. Make sure that your form is browser-compatible. You can use the design checker task pane in the InfoPath 2007 client to perform this task.
  6. Publish your form onto a SharePoint 2007 library. In the wizard, at step 3, check the “Enable this form to be filled out by using a browser” checkbox and finish publishing.
  7. At the end of the publishing wizard, select “Open this document library” and click on Close. This will open the document library in the browser. Click on Settings/Form Library Settings, then click on Advanced Settings and select the “Display as a Web page” option in the Browser-enabled Documents category. If you don’t choose this option, the form will be opened in InfoPath if it’s installed on the client. Otherwise, it’s going to be opened in the browser.

Resolution:

What worked for me actually is the three steps:

1. stsadm -o activatefeature -filename IPFSSiteFeatures\feature.xml -force -url http://URLToYourSite

2. stsadm -o activatefeature -filename IPFSWebFeatures\feature.xml –force -url http://URLToYourSite

3. You need to activate the ‘Office SharePoint Server Enterprise Site Collection features’ feature on Site Collection level

4. iisreset

Infopath 2007 Current Username without code

Posted in Infopath by mauliksoni on July 12, 2010
  • Create a new form by Designing a New Form Template
  • Choose blank form
  • Add a text box to the form (Field1)
  • Go to Tools | Form Options
  • Go to the Open Behavior section and click on Rules
  • Add Action to Set a Field’s Value
  • Choose the field you added above as the field to populate
  • For the value, click on the Fx button and choose Insert Function
  • View All in the Categories drop down
  • At the bottom you’ll see userName, pick it
  • The formula that gets dropped in is userName()
  • Preview the form, you’ll see your UserName in field1
  • File Name concat & translate

    Posted in Infopath by mauliksoni on June 18, 2010

    
    concat(ordernumber, "-", entrynum, "-", formfor, "-Inventory-v", translate(stockno, 99, otheritem))
    
    

    Remove Accidentally added code to Infopath Form

    Posted in Infopath by mauliksoni on May 24, 2010

    How to remove Accidentally Added Code to an InfoPath Form ?

    Tools -> Form Options -> Programming: “Remove Code”

    Follow

    Get every new post delivered to your Inbox.