Answer provided by Ashish is correct, but has 2 issues:
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:
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;
properties.ListItem.SystemUpdate();
}
EventFiringEnabled = true;
properties.Web.AllowUnsafeUpdates = false;
}
}
}
}