How to read Template file-path in InfoPath 2010 Addin Design Mode? RRS feed

All replies

  • Hi KSK,

    Thanks for your post.

    We are doing some researches on this question, and we'll inform you if we get any valuable suggestion.

    Good day,

    Best Regards, Calvin Gao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, November 15, 2011 7:35 AM
  • Unfortunately, this is not possible in Design mode. 

    In Filler mode, you would use the XDocument object.  The XDocument object represents the underlying XML document of a Microsoft Office InfoPath form.  Note that this must be distinguished from the form template.  An InfoPath Form Template, which has a .XSN file extension, contains all of the presentation, formatting, validation, rules, and code that defines what a user should see when filling out a form.  An InfoPath form, on the other hand, has a .XML file extension is only the XML data that a user has filled out.  This distinction makes it easy to use the data in filled out forms in other applications that understand XML.

    When you write code to reference the XDocument object, that code will only make sense in the InfoPath 2010 Filler.  In the InfoPath 2010 Designer, there is no underlying XML document being filled out, so that property will not be available.  Unfortunately, there is not a corresponding property or object that refers to the InfoPath form template.  InfoPath does not offer a way to programmatically generate or publish form templates.  This is different in other Office applications like Excel and Word and PowerPoint, because in those applications, the data and how it's presented are tied together in the same file, so there is no distinction.

    Regards, Joel Alley - Microsoft Online Community Support
    Tuesday, November 15, 2011 9:42 PM
  • I found a work around but isn't clean enough.

    Instead of normally opening a template from InfoPath 2010 Designer, right click on the template and say design (and make sure InfoPath 2010 Designer isn't already open). Using Environment.GetCommandLineArgs() you will see the Template file path in the 3rd argument.

    This isn't much clean, because if you already have InfoPath 2010 Designer running then there is no way you get the 3rd argument. And if you open another Template in design mode just the same way then you will notice the 3rd argument is the first template path.

    Now INFOPATH.exe is the process where all these Templates are running underneath. I could potentially write something and identify the list of files this process is holding on a client PC, then I wasn't able to point out the active template. Then I used System.Diagnostics.Process.GetCurrentProcess().MainWindowTitle to match the template name. But again, it is not clean. If there are two templates with the same Template file name open from different folder, the WindowTitle isn't going to work.

    I want a clean solution. 

    Wednesday, November 16, 2011 3:15 AM