2

I am working in a SharePoint online based environment and I need to fetch the thumbnail url for a document in a library programmatically, using the .Net client object model (not EcmaScript). Is that possible?

  • Hi. I have edited the question - hoping it should be clearer now. Can you please confirm that I have interpreted your needs correctly and you want to use the .net client object model and not the ecmascript based one? I assumed that since you referred to "Microsoft.SharePoint.Client" but I wanted to be sure. – SPArchaeologist Mar 14 '14 at 8:14
  • yes, I want use .net client object model – Ariel Zhang Mar 18 '14 at 14:41
1

List item EncodedAbsThumbnailUrl property stores image thumbnail url, the following example shows how to get it:

using (var ctx = new ClientContext(webUri))             
{
    var list = ctx.Web.Lists.GetByTitle(pictureLibraryTitle);
    var item = list.GetItemById(itemId);
    ctx.Load(item, i => i["EncodedAbsThumbnailUrl"]);
    ctx.ExecuteQuery();

    Console.WriteLine(item["EncodedAbsThumbnailUrl"]);
}
  • I have tried it using REST API and got error "The field or property 'EncodedAbsThumbnailUrl' does not exist" – Atish Dipongkor - MVP Oct 22 '15 at 14:48
  • Tried using CSOM. Now the error is "Column 'EncodedAbsThumbnailUrl' does not exist" – Atish Dipongkor - MVP Oct 22 '15 at 15:01
  • Like the error message says, the specified approach allows only from Picture library (contains Picture content type) and nothing more.. – Vadim Gremyachev Oct 22 '15 at 15:08
  • OP has asked for "document library". EncodedAbsThumbnailUrl exist in Picture Library I know – Atish Dipongkor - MVP Oct 22 '15 at 15:17
  • Field value is only set when the library has property "ThumbnailsEnabled" set to "true". – Shihan Feb 25 '16 at 10:06
0

I decided to implement this way.

    public static string GetEncodedImageUrl(SPWeb web, string url, Guid fieldId)
    {
        try
        {
            if (!string.IsNullOrEmpty(url))
            {
                string webImageUrl = web.GetFile(url).GetListItem()[fieldId].ToString();
                if (!string.IsNullOrEmpty(webImageUrl))
                {
                    return webImageUrl;
                }
            }
        }
        catch
        {

        }

        return url;
    }

    public static string GetEncodedThumbnailUrl(SPWeb web, string url)
    {
        return GetEncodedImageUrl(web, url, SPBuiltInFieldId.EncodedAbsThumbnailUrl);
    }

    public static string GetEncodedWebImageUrl(SPWeb web, string url)
    {
        return GetEncodedImageUrl(web, url, SPBuiltInFieldId.EncodedAbsWebImgUrl);
    }

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.