0
votes

I have to generate an hyperlink in sharepoint based on sql table like this:

+----+----------------------------+
| ID | path                       |
+----+----------------------------+
| 1  | file://test/9932323.pdf    |
+----+----------------------------+
| 2  | file://test/1653156423.pdf |
+----+----------------------------+

Actually there is this code to generate html link:

<a href="{$thisNode/@PATH}"><asp:Label runat="server" id="ff1{$ID}" text="{$thisNode/@PATH}" /></a>

I cannot modify SQL table (dinamically generated) but I have to substitute:

/test/ with /test.abc.local/

and

displayed text with filename only ("path" field substring after last '/')

How can I to that without creating new view or calculated fields?

I tried with:

<a href="{REPLACE($thisNode/@PATH),12,1,'.abc.local/')}"><asp:L ...

but with no success. (I'm really newbie in Sharepoint)

thanks

2

2 Answers

1
votes

I'm not going to remove the previous answer because it still valid and it is pretty handy if somebody comes across the same issue, so the RegEx() expression you will have something like this:

 /(file\:\/\/)/g

Using the expression above you can find the string you want, so the example below gives you all the LABELS on a page, and from there you can use the following:

.replace( new RegExp("/(file\:\/\/test)","gm"),"/test.abc.local")

Using the expression above you can find the string you want, so the example below gives you all the LABELS on a page, and from there you can use the following:

$('input[type=text]').each(
    function(index)
    {  
       console.log(' text: ' + $(this).val() +  ' replace: ' +  $(this).val().replace( new RegExp("(file\:\/\/test)","gm"),"/test.abc.local") );
    }
);
1
votes

If I understood your question correctly, I would strongly suggest you to use RegEx(), it is possibly the most handy thing ever created to handle string find/replacement.

You can put a JavaScript function to perform the RegEx() substitution on the page inside of a <script language="javascript"></script> , then on your <asp:label> you will replace the output for calling this function by passing the string @thisNode/@PATH to the JavaScript function you wrote, which will find and replace the substring for the desired output