Pat’s .Net and Sharepoint Blog
In the Microsoft Sharepoint and .Net Trenches

Using a Replace Web Service in a Sharepoint Web Based InfoPath form

December 10th, 2008 . by <Patrick/>
Due to the lack of an easy way to do a find and replace in InfoPath, I developed a simple web service with a web method called replace that uses managed code to call the replace method of the string data type. Here’s how I call the web method in a browser-based Sharepoint InfoPath form.

First create a form like so..

With fields txtFind, txtReplace and txtText

The idea in this sample form is to replace mother with sister in the text “Don’t forget to call your mother today!”
The next thing you must to is create a new data connection.

You should first see if your Sharepoint server already has a data connection to the Replace web method

Enter the URL of the site like in the above image and then expand the data connections.

Select the Replace.udcx data connection. If you do not see this data connection you must create a new data connection to receive data and then select the web service

Once you have created the web service data connection you must convert it to a data connection file that you must store in a data connection library in your Sharepoint site.

Now you will be presented with the data connection wizard

The web method requires three parameters:

Text: the text you want to do the search and replace on
stringToFind: the text you want to replace ie mother
stringToReplace: the text you want to replace it to ie daughter
escapeSpaces: If you are having difficulty with spaces in your strings and need to use %20 then set this to true otherwise default it to false

For now don’t set default values and click on next, next deselect Automatically retrieve data when form is opened and then click on finish
Your data connection has now been created

So the next thing we need to do is create some rules for our button

The rule will have the following actions - set each of the parameters of the data connection , then query the data connection and then set the txtText value to the result of the data connection query

For the first rule we set the text parameter of the Replace datasource to the value of the txtText field. (make sure to select the Replace data source and not the main data source)

Then create the following actions so that it looks something like this:

Now test out your rule by previewing the form

Click on the Replace button and the text shoudl read Don’t forget to call your daughter today!

Here’s the code for my web method:

_
Public
Function Replace(ByVal text As String, ByVal stringToFind As String, ByVal stringToReplace As String, ByVal escapeSpaces As String) As String

If escapeSpaces.ToUpper = “TRUE” ThenstringToFind = stringToFind.Replace(” “, “%20″)

End If

Return text.Replace(stringToFind, stringToReplace)

End
Function
 


Infopath Forms Services Form opens in browser but as XML

October 26th, 2008 . by <Patrick/>

When opening an infopath form the XML code appears in the browser.
Open Infopath go into Tools / Options
Check – Check whether Microsoft Office is the default program for opening and editing .xml files

Infopath Options


Updating Sharepoint 2003 Infopath Forms to 2007

September 26th, 2008 . by <Patrick/>

When you migrate a form library from Sharepoint 2003 to Sharepoint 2007 references to the Form template will still point to the 2003 form library.
If you need to update the reference Sharepoint has a relink documents feature to individually re-link the xml forms to the appropriate template.
Unfortunately this process can be rather cumbersome especially if the form library contains sub folders. To alleviate this painful process
I developed a tool that with go through an entire directory structure recursively and do a find and replace on the template (.XSN) file.
What you will need to do is go into the explorer view of the form library, copy all files and folders to a location on your local hard drive.
Then open up the “UpdateInfopathTemplate” utility and update all the xml forms. Then copy all the forms back to the destination form library in 2007.

Click here to download the utility