Freigeben über


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

Requirement:

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"];

            properties.ListItem.Update();

        }

    }

}

Comments

  • Anonymous
    January 08, 2008
    PingBack from http://msdnrss.thecoderblogs.com/2008/01/08/sharepoint-2007-mosswss-issue-with-lookup-column-to-doc-lib-name-field-3/

  • Anonymous
    January 08, 2008
    Requirement: You have created a document library and you have created another list where you wanted to

  • Anonymous
    December 05, 2008
    Can you post the feature xml files for this custom evnet handler? Thanks very much.

  • Anonymous
    December 16, 2008
    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.

  • Anonymous
    February 03, 2009
    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.

  • Anonymous
    February 04, 2009
    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 http://www.sharepointboost.com/ Thanks a lot!

  • Anonymous
    June 05, 2009
    Where do you put the file once it is created?

  • Anonymous
    January 24, 2010
    The comment has been removed

  • Anonymous
    July 27, 2012
    Instead of using properties.ListItem.Update(); use properties.ListItem.SystemUpdate(false); This method will not affect the modified (by) field and version number.