title: Sharepoint Services 3.0 : itemAttachmentAdded Method: How to update a column after an attachment is added to a list item
body: <p>I have a custom List called "NameList". I have just two columns in it. Say First Name (Single Line / Text) and Last Name  (Single Line / Text). What I am trying to do is when a user adds a "New Item" to the list. He just has to fill in the first name. Then he adds an an attachment using the "attach file" option and clicks OK. When he clicks OK, I want the last name to automatically update to say "Matthews". Because What I am trying to accomplish is to just be able to update a column (field) when an atachment is added. This is the code I have. Can someone tell me where I am going wrong.</p>
  
  <p>Also it is not working one little bit. I am also brand new to sharepoint development, and I did search for information as much as I can before coming here. The last name column just wont be populated.</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using Microsoft.SharePoint;
  
  namespace UpdateNameList
  {
      public class NameListItemEventReceiver : SPItemEventReceiver
      {
      public override void ItemAttachmentAdded(SPItemEventProperties properties)
      {
          base.ItemAttachmentAdded(properties);
          try
          {
          SPSecurity.RunWithElevatedPrivileges(delegate()
          {
              using (SPSite site = new SPSite("http://cse-sp01/sites/SPPilot"))
              {
              using (SPWeb web = site.OpenWeb())
              {
                  try
                  {
  
                  web.AllowUnsafeUpdates = true;
                  SPList list = web.Lists["NameList"];
                  int listItemId = properties.ListItemId;
                  SPListItem listItem = list.Items.GetItemById(listItemId);
                  listItem["Last Name"] = "Matthews";
                  listItem.Update();
                  web.AllowUnsafeUpdates = false;
                  }
                  catch (Exception ex)
                  {
                  properties.ErrorMessage = "Something went wrong??";
  
                  }
  
  
  
              }
              }
          });
  
          }
          catch (Exception ex)
          {
  
          properties.Cancel = true;
          properties.ErrorMessage = "Error encountered";
          }
  
  
      }//End of Void ItemAttachmentAdded
      }
  }//End of namespace
  </code></pre>