Thursday, 29 November 2012

How to open InfoPath form in browser from workflow status page even though InfoPath client is installed


Hello,

Today again with new SharePoint challenge and solution/observation found.

In our project we have browser enabled InfoPath form and workflow. Whenever we tried to open InfoPath form from workflow status page (WrkStat.aspx) page, if InfoPath client is installed on client machine then it always opened InfoPath form in InfoPath client even though InfoPath form is browser enabled.

Our customer has requirement that InfoPath form must be opened in browser irrespective of InfoPath client is installed or not.

So after doing research we found an alternative, if we add a query string parameter to InfoPath form XML URL, ?OpenIn=Browser then InfoPath form always opens in browser even though InfoPath client is installed.

Now to implement this solution we have two options,

1.   Either modify OOB workflow status page
2.   Copy and have our own separate workflow status page and then change it

Definitely first option is not the recommended solution. So we copied OOB workflow status page and then modified it.

In workflow status page, there is variable called StrUrlItem which contains the URL of InfoPath form xml. The original code is like

<TD nowrap width=180>
<%
      if (!string.IsNullOrEmpty(StrUrlItem))
            {
%>
            <a href=<%SPHttpUtility.AddQuote(SPHttpUtility.HtmlUrlAttributeEncode(StrUrlItem),Response.Output);%> onclick=<%SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(StrOnClickItem),Response.Output);%>>
<%
      }
      SPHttpUtility.HtmlEncode(StrNameItem,Response.Output);
      if (!string.IsNullOrEmpty(StrUrlItem))
      {
%>
            </a>
<%
      }
%>
</TD>

So we changed the above code and made it as follows

<TD nowrap width=180>
<%
      if (!string.IsNullOrEmpty(StrUrlItem))
            {
                StrUrlItem = StrUrlItem + "?OpenIn=Browser";
%>
            <a href=<%SPHttpUtility.AddQuote(SPHttpUtility.HtmlUrlAttributeEncode(StrUrlItem),Response.Output);%> onclick=<%SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(StrOnClickItem),Response.Output);%>>
<%
      }
      SPHttpUtility.HtmlEncode(StrNameItem,Response.Output);
      if (!string.IsNullOrEmpty(StrUrlItem))
      {
%>
            </a>
<%
      }
%>
</TD>

Now once workflow status page get customized we need to change the URL of workflow status page in workflow.xml file as

<StatusPageUrl>_layouts/{Our folder}/WrkStat.aspx</StatusPageUrl>

and we are done.

Thanks!

As usual your comments / feedback / suggestions are most welcome!

Enjoy SharePoint J

No comments: