Monday, 1 July 2013

Thumbnail and Preview File from Picture Library Programmatically

After googling, I found exact information from this article:

Get Thumbnail File:
string urlthumbnail = oitem["EncodedAbsThumbnailUrl"].ToString();
Above will return thumbnail view url

SPFile filethumbnail = olist.RootFolder.SubFolders["_t"].Files[urlthumbnail];

Above will return file object and you can get absolute url

you can get absolute url of file 
string absUrl = Convert.ToString(oItem[SPBuiltInFieldId.EncodedAbsUrl]);

Get Preview File:
string urlpreview = urlthumbnail.Replace("_t""_w");
SPFile filepreview = olist.RootFolder.SubFolders["_w"].Files[urlpreview];


  1. Just a note: you can also use oitem["EncodedAbsWebImgUrl"].ToString() to get the url of the preview image directly.