June 24, 2013

Detach a media from the code

Here is a very small usefull function to detach the media from the c# code in sitecore:
private void DetachMedia(MediaItem mediaItem) 
{ 
 MediaUri mediaUri = MediaUri.Parse(mediaItem); 
 Media media = MediaManager.GetMedia((mediaUri)); 
 media.ReleaseStream(); 
 Context.ClientPage.SendMessage(this, "item:refresh(type=attachment)"); 
}

No comments:

Post a Comment