Issue with XMLFormView.Uri Property in Browser based InfoPath Forms and Work-around

XMLFormView.Uri property of a InfoPath Form should return the URL of the Form itself. But it works if you open the form in InfoPath client and does not work if you open it in browser. When you open it in browser, this property gives you output like: “New Form” instead of the actual URL.

Here is a repro:

1.Set up a form Template with a text field and a button and save it with name TestFormTemplate
2. Use this code behind using VSTA:
namespace TestFormTemplate
{
public partial class FormCode
{

public void InternalStartup()
{
((ButtonEvent)EventManager.ControlEvents["CTRL2_5"]).Clicked += new ClickedEventHandler(CTRL2_5_Clicked);
}
public void CTRL2_5_Clicked(object sender, ClickedEventArgs e)
{
XPathNavigator docXN = this.CreateNavigator();
XPathNavigator xn = docXN.SelectSingleNode("/my:myFields/my:fname", this.NamespaceManager);
xn.SetValue(this.Uri.ToString());
}
}
}
3. Publish the Form as a Template of a Form Library in a (IPFS Enabled) MOSS Site
4. Create a new Form and save it with a name (ex. Form1).
5. Open Form1.xml in InfoPath Client and click on the button. This will give the URL to the Form1.xml.
6. Open this form in Browser and the same action will give "New Form”.

Work-around:

If you want to get the URL of the form, use HTTPContext. You can get all of the querystring variables in this:

System.Web.HttpContext.Current.Request.QueryString.

You have to purse the string to find the value of XmlLocation variable.

When the form is opened for the first time, there is no XmlLocation variable. But once you open a form 2nd time you will find it.