• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1188
  • Last Modified:

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

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
  • 2
1 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?

jimstjohnAuthor Commented:

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
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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now