Tags

,

  public static void DeleteAllAttachements(int id)  
        {   
            using (SPSite site = new SPSite("http://basesmcdev2/sites/tester1"))  
            {  
                using (SPWeb web = site.OpenWeb())  
                {  
                    SPListItem listItem = web.Lists["myattachments2"].GetItemById(id);  
 
                    List<string> fileNames = new List<string>();  
 
                    foreach (string fileName in listItem.Attachments)  
                    {  
                        fileNames.Add(fileName);  
                    }  
                      
                    foreach(string fileName in fileNames)  
                    {  
                        listItem.Attachments.Delete(fileName);                        
                    }  
                    
                    listItem.update();
                }   
            }                     
        } 
Advertisements