Here's what I need to do for a SharePoint 2010 list: Allow users to select the filename from a dropdown showing the items in the Documents library. But the "Add new item" form of the list doesn't show anything from the Documents library.

The lookup column has these properties:

Get information from:  
In this column:  
  [ Title ]

It points to the Title field of the Documents (there wasn't an option for the Name column).

What am I doing wrong? Thanks


The alternate way is:

  1. Create a custom workflow to copy Name in Title file on upload of new document.

Steps for custom workflow

  1. After that, whenever you upload a new document, the Title will be automatically populated on which you can do a lookup.

Hope this helps!!!!

  • Thanks, Ashish. A followup question: When adding items to the list, I don't see the Title field of the Documents library. I've modified the "All Items" view to no avail. Shouldn't the lookup column appear as a dropdown when adding new items? – Alex C Dec 10 '11 at 10:31
  • 1
    If I understand correctly, Title will not be displayed in List. You can only display custom column just created. – Ashish Dec 10 '11 at 10:37
  • 1
    Alex, please mark it as answer if the resolution worked for you :) – Ashish Dec 10 '11 at 10:45

Answer provided by Ashish is correct, but has 2 issues:

  1. When adding a big number of files (drag&drop) some of the titles are not populated.
    This can be fixed with a modification of the workflow as below: Workflow

  2. Another problem is that folders also have Title column filled in and when you create a lookup column for Title, you get both folders and files to select. Let's say your document library has: "Folder 1" -> "File 1", "My File 1"
    "Folder 2" -> "Another File"

Your selection list will have:
- Another File
- File 1
- Folder 1
- Folder 2
- My File 1

If you want only files to be selected, the better option is to write an event receiver for Document Library, like this (you may want to run this code on update as well for the existing documents):

public class EventReceiver1 : SPItemEventReceiver
    const string DOCUMENT_NAME_FIELD = "DocumentName";

   /// <summary>
   /// An item was added.
   /// </summary>
    public override void ItemAdded(SPItemEventProperties properties)
        // Run only on Document content type
        if (properties.ListItem.ContentTypeId.ToString().Substring(0, 6) == SPBuiltInContentTypeId.Document.ToString())
            // Wait for the document to be checked in
            while (properties.ListItem.File.CheckOutType != SPFile.SPCheckOutType.None) { };

            // Create DOCUMENT_NAME_FIELD column if it doesn't exist
            if (!properties.ListItem.Fields.ContainsField(DOCUMENT_NAME_FIELD))
                properties.ListItem.Fields.Add(DOCUMENT_NAME_FIELD, SPFieldType.Text, false);

            // Update DOCUMENT_NAME_FIELD if it's not set properly
            if ((properties.ListItem[DOCUMENT_NAME_FIELD] == null) ||
                (properties.ListItem[DOCUMENT_NAME_FIELD].ToString() != properties.ListItem.Name))
                properties.Web.AllowUnsafeUpdates = true;
                EventFiringEnabled = false;
                lock (this)
                    properties.ListItem[DOCUMENT_NAME_FIELD] = properties.ListItem.Name;
                EventFiringEnabled = true;
                properties.Web.AllowUnsafeUpdates = false;

Try using Name instead of Title, cause Title can be empty for files in Doc Lib

  • Thanks, default. The only problem: Name doesn't appear as an option. These are the items showing: Title, Document ID Value, ID, Created, Modified, Copy Source, Version. And when creating a new item in my list, it won't show even the title field from the Documents library. As this question indicates, it's not possible to show Name: stackoverflow.com/questions/493734/… – Alex C Dec 10 '11 at 10:23
  • 1
    Correct me if I am wrong. You do not get Name as column in Lookup. – Ashish Dec 10 '11 at 10:24
  • You're right, Ashish. What's the best way to point to the file in the Documents library from another list? Should I simply add a Publishing Hyperlink column and copy the link manually? That seems right now as the only option. – Alex C Dec 10 '11 at 10:28
  • 1
    Correct. Add a new content type of "Link to Document" and point the link of uploaded document in the hyperlink. – Ashish Dec 10 '11 at 10:32
  • 2
    It seems not possible to create a lookup to name column, thus you can create an Event Receiver on ItemAdded or a SPD workflow to fill in title field, based on filename, then use Title in Lookup, also you can make title required using SP API, and user will always need to fill it when uploading document – Yuri Leontyev Dec 10 '11 at 10:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.