Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Gets attachment from Sitec0ore MediaItems
private static void GetAttachmentsFromMediaItems(List<string> mediaItemIds, List<Attachment> attachments)
foreach (string mediaItemId in mediaItemIds)
var actualAttachment = new MemoryStream();
MediaItem mediaItem = Sitecore.Context.Database.GetItem(mediaItemId);
actualAttachment.Position = 0;
var attachment = new Attachment(actualAttachment, mediaItem.Name, mediaItem.MimeType);
attachment.ContentDisposition.Size = actualAttachment.Length;
attachment.ContentDisposition.FileName = mediaItem.Name;
if (attachment != null)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment