locked
Add hyperlink to document in Infopath form RRS feed

  • Question

  • Hi,

    I have a file in a document library in the site.

    I have a Infopath form, in which i want to add a link to the document. I have added a hyperlink control, but not sure how to add the server name as the server name would change depending on various environments.

    The document is in : http://serverip/DocLibName/Myfile.pdf

    I tried like this: "/DocLibName/Myfile.pdf" and "~/DocLibName/Myfile.pdf"

    But It does not work.

    How to add this as a hyperlink in the Infopath form.

     Thank you


    • Edited by Venkatzeus Thursday, September 22, 2011 7:29 AM
    Thursday, September 22, 2011 7:27 AM

Answers

  •  

    Add a field to the default group(my:fields) in datasource of the infopath form and name it as hostname

    In the FormEvents_Loading event in Form.cs file of the infopath form, populate the new field created as follows

    MainDataSource.CreateNavigator().SelectSingleNode("\my:fields\my:hostname").SetValue(this.Template.Uri.Host)

    \my:fields\my:hostname  -- xpath to the field created

    With this the host name is always populated with the host name of the server the form template is deployed.

     

    Edit the hyperlink that should point to the pdf

      General Tab -> Link ->select Data Source

      Populate the Data source with the following

        concat("http://", /my:fields/my:hostname, "/DocLibName/Myfile.pdf")

    On the successful form load ,the concat operation creates the hyperlink dynamically by retrieving the hostname from the field in datasource.

    • Edited by TMK555 Thursday, September 22, 2011 3:08 PM
    • Marked as answer by Venkatzeus Friday, September 30, 2011 6:21 AM
    Thursday, September 22, 2011 3:07 PM

All replies

  •  

    Add a field to the default group(my:fields) in datasource of the infopath form and name it as hostname

    In the FormEvents_Loading event in Form.cs file of the infopath form, populate the new field created as follows

    MainDataSource.CreateNavigator().SelectSingleNode("\my:fields\my:hostname").SetValue(this.Template.Uri.Host)

    \my:fields\my:hostname  -- xpath to the field created

    With this the host name is always populated with the host name of the server the form template is deployed.

     

    Edit the hyperlink that should point to the pdf

      General Tab -> Link ->select Data Source

      Populate the Data source with the following

        concat("http://", /my:fields/my:hostname, "/DocLibName/Myfile.pdf")

    On the successful form load ,the concat operation creates the hyperlink dynamically by retrieving the hostname from the field in datasource.

    • Edited by TMK555 Thursday, September 22, 2011 3:08 PM
    • Marked as answer by Venkatzeus Friday, September 30, 2011 6:21 AM
    Thursday, September 22, 2011 3:07 PM
  • Hi,

    Thank you very much for the reply

    Friday, September 30, 2011 6:21 AM