“Send To” function in WSS 3.0 does not copy look-up fields

The "Send To" function of WSS 3.0 does not copy look-up fields when you copy a non-Office document (like doc, xls etc) for 1 list to another. This is because the scope of the Look-Up field is the same web that the source document is at; whereas the “Send To” feature allows you to copy an item to any list on any SharePoint site, even if not in the same server. The Look-Up field needs to exist in an existing list on the target site. The sending site has no way to ensure this, and therefore does not attempt to copy this meta-data.

In the case of Office documents, the fields are stored as meta-data inside the documents itself. This issue is only for non-Office documents.

The easiest workaround would be to create an event handler (ItemAdded event) for the destination list, which fires every time an item is added to the target list. The code inside this handler can use the list item's "CopySource" property to identify the source of the document/item, and then copy the values over from the item's fields.

Following is an example of how an ItemAdded event handler can look like for this situation.

    1: public override void ItemAdded(SPItemEventProperties properties) 
    2: { 
    3:     DisableEventFiring(); 
    4:     try 
    5:     { 
    6:         using (SPSite site = new SPSite("http://site:80/")) 
    7:         { 
    8:             using (SPWeb web = site.OpenWeb()) 
    9:             { 
   10:                 //Target list 
   11:                 SPList list = web.Lists[properties.ListId]; 
   12:                 SPListItem item = list.Items[properties.ListItem.UniqueId]; 
   14:                 //Get the source URL 
   15:                 string source = item.CopySource; 
   17:                 //Determine the list name 
   18:                 char[] delimiters = new char[1] { '/' }; 
   19:                 string[] subStrings = source.Split(delimiters); 
   20:                 SPList sourceList = web.Lists[subStrings[3]]; 
   21:                 Guid guid = GetItemID(sourceList, subStrings[4]); 
   23:                 //Get the source item SPListItem 
   24:                 sourceItem = sourceList.Items[guid]; 
   26:                 //Get the look up field and save 
   27:                 item["LookUp"] = sourceItem["LookUp"]; 
   28:                 item.Update(); 
   29:             } 
   30:         } 
   31:     } 
   32:     catch (Exception ex) { } 
   33:     finally 
   34:     { 
   35:         EnableEventFiring(); 
   36:     } 
   37: } 

As always… Happy Coding image