Recently, I worked on a task wherein I had to return the size of the Media Item of a website in Sitecore.
This is so very easy. It can be found with the help of the following class : Sitecore.Data.Items.MediaItem.
Also, the size is available in Bytes.
A simple code finding out the solution was as follows:
[sourcecode highlight=”10″ language=”csharp”]
using Sitecore;
using Sitecore.Data.Items;
public string CheckMediaSizeInDB(string mediaItemID)
{
Item myItem = Context.Database.GetItem(mediaItemID);
Diagnostics.Assert.IsNotNull(myItem, "Item with ID ‘" + mediaItemID + "’ does not Exist!");
MediaItem mymediaItem = new MediaItem(myItem);
// The current value is in Bytes!
string MediaSize = mymediaItem.Size.ToString();
return MediaSize;
}
[/sourcecode]
Happy Sitecoring! 🙂
1 thought on “Checking the Size of a Media Item in Database”