1

I'm using dillenmeister's Trello.Net API wrapper, and I see that removing an attachment from a card was added a couple months ago, but the call that I'm using (Trello.Cards.RemoveAttachment()) calls for a CardId and an IAttachmentId. I've figured out how to create a CardId (new CardID(Card.ID)), but I'm not seeing how to create the IAttachmentID that it's looking for.

I have the attachment object, and can get the ID from there, but that is of type string.

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
B-Wint
  • 177
  • 1
  • 8

1 Answers1

1

The Attachment class itself implements IAttachmentId.

// Example: Remove all attachments with the name "DevSupport" from a card 
var card = trello.Cards.WithId("a card id");
foreach (var attachment in card.Attachments.Where(a => a.Name == "DevSupport"))
    trello.Cards.RemoveAttachment(card, attachment);

It's similar for many other objects, for example the Card class implements ICardId. You do not need to create a CardId object if you have a Card. Just use the actual Card.

// Example: Fetch all members assigned to a card
var card = trello.Cards.WithId("a card id");
var members = trello.Members.ForCard(card);

There might be a need for an AttachmentId class anyway though. What is your use case?

dillenmeister
  • 1,627
  • 1
  • 10
  • 18
  • When we move a `Card` to one `Board` in particular we are adding a cover image, and we want to remove only that image when the `Card` is returned to any other `Board`. When adding the `Attachment`' I'm giving it a `Name` as well, so here is the code that I was planning on using to remove: foreach (Card.Attachment att in attch) { if (att.Name.ToString().Equals("DevSupport", StringComparison.OrdinalIgnoreCase)) { t.Cards.RemoveAttachment(cID, att); } } Where `cID` is a `CardID`. – B-Wint Jan 21 '13 at 21:11
  • I updated the first example to be more relevant to what I think you want to do. – dillenmeister Jan 21 '13 at 21:23
  • Yes, the code looks great and works like I was hoping. Thanks. – B-Wint Jan 21 '13 at 21:54