31 October 2012

Links to Documents in DVWP with Linked Sources

I received a request from a co-worker today to create an aggregated view of multiple document libraries within a root site collection's sub-sites at the top-most site collection level. The request seemed pretty straight forward and I immediately went off to start creating a Data View Web Part.

I first created four individual SOAP connections through SharePoint Designer for each of the document libraries on the four sub-sites. I then used the Linked Sources option to combine all of the SOAP connections into one larger connection that could be dropped into an empty data view.

All went well with creating this linked source and I was able to display the information grouped by the document's source location. I went ahead and switched the  Document Title to a hyperlink, in hopes to use the "URL_path" column as a means of linking directly to the document, so that even at the top-level site collection where this aggregated library lives, users would be able to click on the title of the document and open it.

I found however, that this column was not available to me. I did find that the @ows_FileRef column was available, which links to the relative URL of the document (i.e. - /sites/sub-siteName/document1.docx). I went ahead and cleared out the {@FileRef} hyperlink at the bottom of the hyperlink options screen and replaced it with "http://myservername/{@FileRef} assuming that this would take append the relative location of my file to the server name, creating a full path to the file - right?

Yes and no.

It created the URL just as I wanted it, but I found that right before the relative /sites/subsiteName/ URL, there were a few extra characters; "3;#". I started perusing the web and found that there were some other instances of similar things happening, but the characters being slightly different; maybe "1;#" or "2;#", etc.

Thanks to the web, I found that you could go into the actual code view and create a new XSL variable and fix the URL.



As you can see from the code above, we are taking the default table row and before creating the hyperlink to the document, creating a new variable entitled "DocURLtemp". You can see from the "select="substring-after" attribute that we are creating a copy of the "ows_FileRef" variable, but only after the "#" symbol (remember, we liked the relative URL that the FileRef variable provided us, but wanted to exclude the erroneous "3;#" that came before it - so this attribute is taking a copy of the FileRef variable but excludes those erroneous characters).




So with that new variable declared, we can now tweak our proceeding URL to include our server URL and then include the new variable we created.

Now after making these changes and saving your page, your document titles should link directly to their respective files!

-Steve


No comments:

Post a Comment