How do I add a custom column to a SharePoint Document Library View

Posted on 2009-12-15
Last Modified: 2012-05-08
First things first... I'm a SharePoint novice.

I want to create a view in a SharePoint document library that includes a thumbnail view of the documents (doc, xls, pdf, etc).
None (repeat NONE) of the documents in the library will be picture files (jpeg, png, gif, etc.)

I have already written a DLL that implements the IShellFolder interface that creates the thumbnails at any size desired.

How do I create a view against a document library where I can programmatically add the column to the view, then create the thumbnail image (bitmap) from the document and insert it in the proper row/column in the view??  I figure I'd check to see if the thumbnail of the document has been cached (I am going to put them in the _t subfolder of the document folder), create (or update) the thumbnail if necessary, then retrieve the thumbnail image for use in the view.  I've seen numerous examples of SharePoint code, but none that work against a user defined view in a document library.

Thanks in advance
-- Jim
Question by:jimstjohn
    LVL 3

    Expert Comment

    LVL 16

    Accepted Solution

    Sound like a cool little project...

    Not exactly sure if this is what you are asking, but I'll give it a try.

    For the document library, add a "hyperlink or picture" column (document library->document library setting->create column). Call it PictureURL

    For the same document library create a VIEW that includes the PictureURL column.

    Now your code will need to generate the thumbnail image and place it in the _t subfolder. It then will also need update the PictureURL value to point to the location of the image file.

    You can either schedule the code to iterate through your document library on hourly/nightly basis or potentially have it run as a Event Handler when the file is uploaded or updated.

    Does that help?

    LVL 1

    Author Comment


    Your comment was ***EXTREMELY*** helpful!!  It tells me I'm pointed in the right direction!!!

    I created the "ThubnailImage" picture column (on a site level basis), and modified the site's document content type by adding the new column to it.

    The problem I'm having is that I can't figure out how to update the field in the SPFile object.  The SPFile object doesn't expose a Fields collection, but the SPListItem
    object associated the the SPFile object does.

    I am iterating through the document libraries, getting access to each SPFile object within.  

    foreach (SPFile myFile in myDocumentLibrary.Files)
       myFile.Item.Fields["ThumbnailImage"] = urlToImageFile;

    The statement

    myFile.Item.Fields["ThumbnailImage"] = urlToImageFile;

    is flagged as an error by the compiler -- Property or indexer 'Microsoft.SharePoint.SPFieldCollection.this[string]' cannot be assigned to -- it is read only

    So, I've got the reference to the SPFile object, and I can get at the associated SPListItem object, but how the heck do I update the field?

    Thanks again,
    -- Jim
    LVL 16

    Expert Comment

    I am not an expert on the SharePoint Object Model, but I don't think you suppose to use the SPFile obkect. The SPListItem sounds right though

    Featured Post

    PRTG Network Monitor: Intuitive Network Monitoring

    Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

    Join & Write a Comment

    For SharePoint sites, particularly public-facing ones, there are times when adding JavaScript, Meta Tags, CSS Styles or other content to the page <head> section is more practical than modifying master pages.  For instance, you could add the jQuery l…
    We had a requirement to extract data from a SharePoint 2010 Customer List into a CSV file and then place the CSV file into a directory on the network so that the file could be consumed by an AS400 system. I will share in Part 1 how to Extract the Da…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…
    This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now