views:

931

answers:

2

How do you create a lookup column to a Document Library that uses the 'Name' of the document as the lookup value?

I found a blog post that recommends adding another custom field like "FileName" and then using a item reciever to populate the custom field with the value from the Name field but that seems cheesy. Link to the blog in case people are interested: http://blogs.msdn.com/pranab/archive/2008/01/08/sharepoint-2007-moss-wss-issue-with-lookup-column-to-doc-lib-name-field.aspx

I've got a bunch of custom document content types that I dont want to clutter with a work around that should really work anyway.

+1  A: 

One way you can do this (although not the easiest way) is by creating a custom field type that extends the SPFieldLookup class. SharePoint's field editor for Lookup fields purposefully hides any columns types that aren't supported by Lookup fields, but you can create a field editor for your custom field type that shows them.

However, I have created a Lookup column that points to a Name column in a Document Library before, and it probably doesn't work like you'd expect. While the value stored in the lookup column is valid, it doesn't show up right in List view or on the View Properties form.

The solution you posted may actually be the best way to handle this. Lookup fields require some kludges if you want to handle more complex scenarios, but that's because they're not meant to provide the same functionality as a foreign key relationship in a database.

DylanW
I ended up going the ItemUpdatedReciever route and its actually cleaner than I thought it would be. Thanks for the advice about the custom field- probably saved me some time trying to go down that route.
stlawrence