Search code examples
tfstfs-sdk

How to delete a specific attachment using TFS api 2010, 2012?


How to delete a attachment in attachments collection using TFS api 2010, 2012. I only know wi.Attachments.Clear(); to delete all attachment.


Solution

  • How about this way? I tried and succeeded.

    //wi is a WorkItem  
    wi.Open();  
    for (int i = wi.Attachments.Count - 1; i >= 0; i--)  
    {  
        if (wi.Attachments[i].Name == "Attach1.txt")  
        wi.Attachments.RemoveAt(i);  
    }  
    wi.Save();
    wi.Close();