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.SPArcheon - on strike– SPArcheon - on strike2014-03-14 08:14:56 +00:00Commented Mar 14, 2014 at 8:14
-
yes, I want use .net client object modelAriel Zhang– Ariel Zhang2014-03-18 14:41:24 +00:00Commented Mar 18, 2014 at 14:41
Add a comment
|
2 Answers
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 Kumar Dipongkor– Atish Kumar Dipongkor2015-10-22 14:48:26 +00:00Commented Oct 22, 2015 at 14:48
-
Tried using CSOM. Now the error is "Column 'EncodedAbsThumbnailUrl' does not exist"Atish Kumar Dipongkor– Atish Kumar Dipongkor2015-10-22 15:01:52 +00:00Commented 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..Vadim Gremyachev– Vadim Gremyachev2015-10-22 15:08:19 +00:00Commented Oct 22, 2015 at 15:08
-
OP has asked for "document library". EncodedAbsThumbnailUrl exist in Picture Library I knowAtish Kumar Dipongkor– Atish Kumar Dipongkor2015-10-22 15:17:05 +00:00Commented Oct 22, 2015 at 15:17
-
1Field value is only set when the library has property "ThumbnailsEnabled" set to "true".Shihan– Shihan2016-02-25 10:06:18 +00:00Commented Feb 25, 2016 at 10:06
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);
}