1

I changed All Assets view for Images library in SharePoint 2013:

  SPList imageList = web.Lists["Images"];
  var view = imageList.Views["All Assets"];                
  view.ViewFields.DeleteAll();
  view.ViewFields.Add("ThumbnailOnForm");
  view.ViewFields.Add("LinkFilename");
  view.ViewFields.Add("Width");
  view.ViewFields.Add("Height");
  view.ViewFields.Add("Modified");
  view.ViewFields.Add("Editor");
  view.Query = @"<OrderBy><FieldRef Name='Modified' Ascending='False' /></OrderBy>";
  view.DefaultView = true;
  view.Update();                           
  imageList.Update()

but, when I upload images, then the Thumbnail displays blank image. Only when I add "PreviewOnForm" field to view, then Thumbnail displayed correctly.

How can I display Thumbnail using ThumbnailOnForm column?

1

I set view xml with PreviewOnForm column, and now it works:

var viewXML = @"<View Type='HTML' DisplayName='All Assets' ContentTypeID='0x' ImageUrl='/_layouts/15/images/dlicon.png?rev=23'>
                            <Query><OrderBy><FieldRef Name='Modified' Ascending='False' /></OrderBy></Query>
                            <ViewFields>
                                <FieldRef Name='ThumbnailOnForm' />
                                <FieldRef Name='LinkFilename' />
                                <FieldRef Name='ImageWidth' />
                                <FieldRef Name='ImageHeight' />
                                <FieldRef Name='Modified' />
                                <FieldRef Name='Editor' />
                                <FieldRef Name='PreviewOnForm' Explicit='TRUE' />
                            </ViewFields>
                            <RowLimit Paged='TRUE'>20</RowLimit>
                            <XslLink>main.xsl</XslLink>
                            <Toolbar Type='Standard'/>
                            <JSLink>clienttemplates.js</JSLink>
                            <Aggregations Value='Off' />
                          </View>";
SPList imageList = web.Lists["Images"];
SPView view = imageList.Views["All Assets"];
view.SetViewXml(viewXML);
view.Update();
imageList.Update();

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.