There have been many instances where we need to show the document preview in the document library just to give the look and feel of the document uploaded in the SharePoint Library.
In this blog, I will detail out the list of the steps to achieve the functionality using Server Side code or Server object Model.
Before implementing this piece of code, we need to add a picture column in the document library. The below code overrides the existing ItemAttachmentAdded event.
- public override void ItemAttachmentAdded(SPItemEventProperties properties)
- {
- base.ItemAttachmentAdded(properties);
-
- SPListItem item = properties.ListItem;
-
- string attachmentUrl = item.Attachments.UrlPrefix + item.Attachments[0];
-
- item["PicturePreview"] = attachmentUrl;
- item.Update();
- }
Happy SharePointing :-)