Search code examples
c#sharepointinfopath

Find the current view name of the Info-path form on SharePoint


I have a multi-view InfoPath form on SharePoint Site. I need to generate PDFs from the current view of the form using C#. I have done many searches, but no answer so far.

Appreciate your input very much.


Solution

  • If you are using InfoPath 2010 , you can find the name of current view using java script. Within the rendered page, there is an Array variable called "CurrentFormData.g_objCurrentFormData" which holds the current form viewer's data.

    Find the client name of your viewer (e.g.: ctl00_PlaceHolder1_XmlFormView1) and use that read the data. For example:

    CurrentFormData.g_objCurrentFormData[ctl00_PlaceHolder1_XmlFormView1]
    

    This is an array itself in which the 9th element is the name of the current view.

    CurrentFormData.g_objCurrentFormData[ctl00_PlaceHolder1_XmlFormView1][9]
    

    Read that, store it in a hidden server side input field that you can read at the server side.

    This solution is hack though. If Microsoft decide to store that value somewhere else, then this code won't work properly.