Welcome to MSDN Blogs Sign in | Join | Help

Pranab Paul's Blog - Development Tips on SharePoint, Office and Web

------------------------------------------Web Parts, Workflow, InfoPath Form Services, Features, Site Definition, Event Receivers, Excel Services, Business Data Catalog (BDC), Search

News

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();

        }

    }

}

 

Posted: Tuesday, January 08, 2008 8:21 PM by pranab

Comments

SHAREPOINTBlogs.com Mirror said:

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

# January 8, 2008 5:27 PM

Grace said:

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

# December 5, 2008 3:11 PM

Muralee said:

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.

# December 17, 2008 4:45 AM

James Brown said:

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.

# February 3, 2009 2:49 PM

Ben said:

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!

# February 4, 2009 9:14 PM

William said:

Where do you put the file once it is created?

# June 5, 2009 1:28 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

  
Enter Code Here: Required

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Page view tracker