SharePoint 2007 (MOSS/WSS) Issue with lookup column to Doc Lib Name Field


You have created a document library and you have created another list where you wanted to have a lookup type column and wanted to use that lookup column to receive the Name of the documents from the doc lib. But you cannot get the Name field in the drop down for lookup column.


Apparently this is a limitation and there is no direct resolution out of the box.


Anyway, I found a workaround for this and it involves coding. I have created a sample code for a custom Item Event receiver feature. I have created a new field in the doc lib called FileName. Now after activating this feature, once we add any document to the doc lib the value of the Name field will be copied to FileName field. Now this FileName field is available in the lookup dropdown which solves our purpose. Here is the code for the custom feature:


using System;

using System.Collections.Generic;

using System.Text;

using Microsoft.SharePoint;



namespace NameLUpHandler


    public class Processor : SPItemEventReceiver


        public override void ItemAdded(SPItemEventProperties properties)


            if (properties.ListItem.Fields.ContainsField("FileName"))

                properties.ListItem["FileName"] = properties.ListItem["Name"];






Comments (9)
  1. Bileaf ICT Support says:

    Instead of using




    This method will not affect the modified (by) field and version number.

  2. CARPENTIER Olivier says:

    This code can’t work for other languages because properties.ListItem["Name"] works only for column called "Name" (it’s a reference to the display name and not the internal name).

    Use this line to correct it :

    properties.ListItem["FileName"] = properties.ListItem.Name;

    Best regards,


  3. William says:

    Where do you put the file once it is created?

  4. Ben says:

    I know one tool,very small actually, called sharepoint Document auto tittle which claims can auto set tittle to document and can be looked-up easily!

    But from your blog I fond it is not so easy to do this. Am I got it wrong or what happened?

    If you want check it visit

    Thanks a lot!

  5. James Brown says:

    Couldn’t you create a workflow in Sharepoint Designer that sets FileName equal to Name and have it fire for new items?  I did that and I believe I got the same result.

  6. Muralee says:

    Hi Paul

    I have a little variant issue , I need to look up to a list from my document library, say i have a column in the list called document types.How can i add a this look up column to my document library.

  7. Grace says:

    Can you post the feature xml files for this custom evnet handler? Thanks very much.

  8. Requirement: You have created a document library and you have created another list where you wanted to

Comments are closed.

Skip to main content