I've a Picture Library to which I added pictures,now i want to create a Visual Web Part which displays a list of pictures added to library like this

enter image description here

I created the similar design in ascx file like this

<asp:Repeater ID="Repeater1" runat="server">
            <td rowspan="2">
                <img src='<%#Eval("Image") %>' alt="" /></td>
                <asp:Label ID="Label1" runat="server" Text='<%#Eval("Title") %>'></asp:Label></td>
                <asp:Label ID="Label2" runat="server" Text='<%#Eval("Description") %>'></asp:Label></td>

I am not getting what should i write in src field of image to display thumbnails.

Here I wrote '<%#Eval("Image") %>' in code for explanation purpose.


You must use code like this to get image url:

SPList spList = web.Lists["ImagesLibrary"];
SPListItem item = spList.Items.GetItemById(itemID);

//Thumbnail Url
string thumbnailUrl = item[SPBuiltInFieldId.EncodedAbsThumbnailUrl].ToString();

//Picture Url
string pictureUrl = item[SPBuiltInFieldId.EncodedAbsUrl].ToString();

The above Urls are the full Urls of the thumbnail and picture respectively. To get the absolute, relative Urls of the picture the Url can be managed as below.

Uri uri = new Uri(thumbnailUrl);

string relativePath = uri.AbsolutePath;

link to source

  • Thanx it works fine :) – Sid M Dec 18 '13 at 8:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.