Freigeben über


Hyperlinks will not run code in InfoPath

I have seen people coming up with requirements to run VB or C# code from InfoPath using hyperlinks. This could be achieved only using code editor and event handlers. When we insert the path of the code in the addresses, it goes through the default browser and downloads the code instead.

"The hyperlink control enables users to insert or edit a hyperlink on the form. Users editing and viewing the form can click the hyperlink which automatically opens the Web browser to the location that the link points to. This is useful when you are required to input a hyperlink as part of the form."

Workaround:

  • Insert a button in InfoPath form and go to developer tab -> click code editor.
  • Choose the programming language based on your requirements (I have used VB).
  • Make sure that the InfoPath form is in full trust. Otherwise you will get an error message as mentioned in the below article.

https://blogs.technet.com/b/madhan/archive/2015/09/16/common-errors-messages-in-infopath.aspx

  • Add the reference System.Diagnostics and use the namespace in the header "Imports System.Diagnostics".
  • The below code will run the VB script.

Public Sub CTRL1_5_Clicked(ByVal sender As Object, ByVal e As ClickedEventArgs)

Process.Start("C:\Windows\SysWOW64\wscript.exe", "C:\test.vbs")

Note : Modify the path of the VB file. CTRL_5 is the name of the clicked button event handler.

  • The above code will call the test.vbs which will get executed once the button is clicked.

** Please note that this code is not production ready. It has to be tested in the development/test environment.

Thanks to my colleague Ajay for his contribution.