none
infopath how to create a dynamic hyperlink?

    Question

  • I'm trying to populate a field with a URL and display text.

    something like this.

    display text: Taco

    URL: http://www.taco.com

    either with code or joining two fields.


    www.SharePointed.com


    • Edited by eHaze Monday, April 30, 2012 4:24 PM
    Monday, April 30, 2012 4:21 PM

All replies

  • Hi,

    How is the problem?

    You have a hyperlink object in Infopath.

    Regards.


    Tomás González. Twitter://@tgmourino

    Monday, April 30, 2012 4:26 PM
  • Hi,

    in Infopath, add a hyperlink object.

    In the right tab, select the field and edit properties with a right click.

    In this example the hyperlink name object is campo3 and campo4.

    Right click in campo3 and set data type as hiperlink and set the default value: http://www.pepe.com

    Right click in campo4 and set data type as text and set the default value: pepe

    Save changes an you get the hyperlink:

    You can edit this field in the form.

    Regards.


    Tomás González. Twitter://@tgmourino


    Monday, April 30, 2012 4:50 PM
  • Here is what I ended up doing:

                XmlNamespaceManager ns = this.NamespaceManager;
    
                XPathNavigator xnMain = e.Source.CreateNavigator();
    
                XPathNavigator xnLink = xnMain.SelectSingleNode("my:Link", ns);
    
    xnLink.AppendChild("<a xmlns=\"http://www.w3.org/1999/xhtml\" href='" + sURL + "'>" + myDecoder.Filename + "</a>");

    sURL = URL of the file

    myDecoder.Filename = File name


    www.SharePointed.com

    Monday, April 30, 2012 6:32 PM
  • Seems overly complex.  There are two hyperlink objects in InfoPath.  This can make things complicated.

    Firstly, as Tomás González shows in the example above, you can use a Hyperlink control.  A hyperlink control is usually bound to an element on your data source.

    If you just want to display a link - and bind it with expressions, you can actually just insert a hyperlink, this is the "second" hyperlink option within InfoPath, this is done by going to the Insert ribbon, then select Hyperlink.

    What this does is essentially give you a way to render a hyperlink like you can with an expression box.

    You can also use fields from your data source in this particular... hyperlink-expression box.  Unlike the Hyperlink control, your users can't modify the values or replace it with a picture.


    jliu - http://johnliu.net - http://sharepointgurus.net


    • Edited by John Liu Thursday, May 03, 2012 8:43 AM
    Thursday, May 03, 2012 8:42 AM
  • Hi,

    Code to create a hyperlink?

    Wow!

    Like John says, "seems overly complex".


    Tomás González. Twitter://@tgmourino


    Thursday, May 03, 2012 11:46 AM
  • tomas and john,

    there is more to this fun infopath story.

    the fun:

    web form that has an attachment control. 

    when a user attaches a document, code behind moves it to a document library.

    after the document is moved, the attachment control is cleared.

    then populate a hyperlink with the description and path to the document, that now lives in the doc library.

    hence my move to populate the field with code.


    www.SharePointed.com


    • Edited by eHaze Thursday, May 03, 2012 12:26 PM
    Thursday, May 03, 2012 12:25 PM
  • InfoPath is always fun!  :-)

    There are a few ways to do what you said without code - both qRules and Nintex workflows can do the document extraction from InfoPath and replace it with a URL.  OK!  don't shoot me I'm done plugging 3rd party, non-free tools.  (no affiliation).

    Regarding your code, I still think it's not a good idea to write the entire <a> tag in a Hyperlink field.  I think it's a better idea to just write the URL to a field in code, then use either Tomas or my example of a hyperlink with databinding to that field to display it.

    This way, if you need to parse your form later, say through workflow or otherwise, you can get the URL directly, without having to strip out the <a src=" bits again.


    jliu - http://johnliu.net - http://sharepointgurus.net

    Thursday, May 03, 2012 12:38 PM
  • thanks for all the info!

    we are looking into buying K2 or something else.

    thanks again!


    www.SharePointed.com

    Thursday, May 03, 2012 12:42 PM
  • Hi eHaze,

    You've hidden information!!! xD

    regards.


    Tomás González. Twitter://@tgmourino

    Thursday, May 03, 2012 2:22 PM