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?

2
  • 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. Commented Mar 14, 2014 at 8:14
  • yes, I want use .net client object model Commented Mar 18, 2014 at 14:41

2 Answers 2

2

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"]);
}
6
  • I have tried it using REST API and got error "The field or property 'EncodedAbsThumbnailUrl' does not exist" Commented Oct 22, 2015 at 14:48
  • Tried using CSOM. Now the error is "Column 'EncodedAbsThumbnailUrl' does not exist" Commented Oct 22, 2015 at 15:01
  • Like the error message says, the specified approach allows only from Picture library (contains Picture content type) and nothing more.. Commented Oct 22, 2015 at 15:08
  • OP has asked for "document library". EncodedAbsThumbnailUrl exist in Picture Library I know Commented Oct 22, 2015 at 15:17
  • 1
    Field value is only set when the library has property "ThumbnailsEnabled" set to "true". Commented Feb 25, 2016 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);
    }

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.