try
{
// Set the Site Url
SPSite objSite = new SPSite("http://Testsite/");
using (SPWeb objWeb = objSite.OpenWeb())
{
objWeb.AllowUnsafeUpdates = true;
// Get the List
SPList objList = objWeb.Lists["MyList"];
// Get the item by ID
SPListItem objItem = objList.GetItemById(1);
// Get the attachments of the item
SPAttachmentCollection objAttchments = objItem.Attachments;
// Iterate the attachments
foreach (string fileName in objItem.Attachments)
{
// Perform action on the extracted attachment
}
objWeb.AllowUnsafeUpdates = false;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}