Wednesday, September 21, 2011

Display a picture in a dataview web part

from: http://techtrainingnotes.blogspot.com/2009/04/sharepoint-displaying-pictures-and.html


4/27/2009
SharePoint: Displaying Pictures and Thumbnails in a Data View Web Part


This is in response to a question about displaying a thumbnail from a Picture Library in a Data View web part…



Displaying the full size picture is really easy. When selecting your fields for the Data View web part select “Url Path”. This will be added to the XSLT of the Data View web part as:

{@FileRef}

(@FileRef is the XSLT fieldname used for “Url Path”)



The trick is getting the URL to the picture library’s auto-created thumbnail. The thumbnail for “test.jpg” is “/_t/test_jpg.jpg” and is not a field in the SharePoint Designer list of fields. To get it you will need to do some XSLT string work:

concat(@FileDirRef,'/_t/', substring-before(@FileLeafRef,'.'),'_',substring-after(@FileLeafRef,'.'),'.',@FileType)

Note: the above will only work if only one “.” exists in the file name. It will fail for a file named my.airshow.picture.jpg

@FileDirRef is the name of the library (airshow%20pictures)

@FileLeafRef is the file name (helicopter.jpg)

@FileType is the file type (jpg)

‘/_t/’ is the path to the auto-created thumbnails

substring-before / after are XSLT string functions

The above “stuff” will convert:

/airshow%20pictures/helicopter.jpg

into

/airshow%20pictures/_t/helicopter_jpg.jpg

which is the path to the thumbnail.



The final tag looks like this:

{@FileRef}



If you would like to let the user click on the thumbnail to see the full picture and meta data then wrap the in a tag and supply the ID of the picture:


{@FileRef}

No comments:

Post a Comment