Create thumbnails for SharePoint document library images

Source: Internet
Author: User
Tags cdata

One of our customers needs to add a thumbnail (Thubmnail) display mode for the images in the document Library, but we know that by default, only the Image Library (Picture Library) supports the thumbnail display mode.

 

Since we know that the Image Library has the Thumbnail function, we can start with the image library and check that there is a field "Thumbnail" in the Image Library ",

You only need to add the "Thubmnail" field to implement the thumbnail function. However, through Site Column, we cannot find this field, that means we cannot simply add the thumbnail function.

 

Let's take a closer look at why Thubmnail exists in the Image Library. The above investigation shows that only the Image Library has the Thubmnail field. Does that mean that the Thumbnail field is added only to the list Schema definition of the Picture Library?

Open the Schema file of Picture Library (14 \ TEMPLATE \ FEATURES \ PictureLibrary \ PicLib), And the Thum field is defined in the Schema.

We can find that Thumbnail is not a field, but a set of fields. Therefore, we need to confirm that all fields will be added when we add Thumbnail to other form types.

 

To confirm that all fields are added, we can add the Picture content type to the document library.

Add the Picture content type as follows and set it to the default type.

Document Library-> List settings-> advanced settings-> allow content type management (selected)

Through the above settings, we cannot add all fields to this document library, because fields such as "EncodedAbsThumbnailUrl" are unique to the image, therefore, we also need to add it to the document library through code.

Create Thumbnail. XML

<Field ID="{ac7bb138-02dc-40eb-b07a-84c15575b6e9}" ReadOnly="TRUE" Type="Computed" Name="Thumbnail" ShowInNewForm="FALSE" ShowInFileDlg="FALSE" ShowInEditForm="FALSE" DisplayName="Thumbnail;" Sealed="TRUE" Sortable="FALSE" Filterable="FALSE" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="Thumbnail">

<FieldRefs>

<FieldRef Name="ImageWidth" />

<FieldRef Name="ImageHeight" />

<FieldRef Name="FSObjType" />

<FieldRef Name="EncodedAbsUrl" />

<FieldRef Name="Description" />

</FieldRefs>

<DisplayPattern>

<IfEqual>

<Expr1>

<LookupColumn Name="FSObjType" />

</Expr1>

<Expr2>0</Expr2>

<Then>

<IfEqual>

<Expr1>

<LookupColumn Name="ImageWidth" />

</Expr1>

<Expr2>

</Expr2>

<Then>

</Then>

<Else>

<IfEqual>

<Expr1>

<LookupColumn Name="ImageWidth" />

</Expr1>

<Expr2>0</Expr2>

<Then>

</Then>

<Else>

<HTML><![CDATA[<a href="]]></HTML>

<URL Cmd="Display" />

<HTML><![CDATA["></HTML>

<IfEqual>

<Expr1>

<Column Name="Description" />

</Expr1>

<Expr2>

</Expr2>

<Then>

<HTML><![CDATA[$Resources:core,Thumbnail;]]></HTML>

</Then>

<Else>

<Column Name="Description" HTMLEncode="TRUE" />

</Else>

</IfEqual>

<HTML><![CDATA[" SRC="]]></HTML>

<Field Name="EncodedAbsUrl" />

<HTML>

<![CDATA[">

</a>

]]>

</HTML>

</Else>

</IfEqual>

</Else>

</IfEqual>

</Then>

</IfEqual>

</DisplayPattern>

</Field>

Add the XML file using the SharePoint Object Model. The Code is as follows:

static void Main(string[] args)
{
//site url
using (SPSite osite = new SPSite("siteURL"))
{
using (SPWeb oweb = osite.OpenWeb())
{
//document library name
SPList olist = oweb.Lists["documetn library"];
//Thumbnail xml path
StreamReader rdr = new StreamReader(@"Thumbnails.xml");

string fld = rdr.ReadToEnd();

olist.Fields.AddFieldAsXml(fld, true, SPAddFieldOptions.AddToDefaultContentType);

olist.Update();

}
}
}

In this way, we have implemented image thumbnails in the library. upload an image and try again.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.