I'm trying to write a query to select media items which have no attachment. Is there some default value for empty images which can be used in a query? I'm trying to use

/sitecore/content/Tennant/Tennant/Company/Brand/Site/Media//*[@@templateid="{EB3FB96C-D56B-4AC9-97F8-F07B24BB9BF7}" and @Blob=""]

but this is returning no items, even though I can clearly see Media Items with no images under the above path.

2 Answers 2


If a media item has no attachment, and the attachment has been detached correctly using the Detach option on the Blob field then details about the media item will be wiped. You can check the the Size field is empty:

/sitecore/#media library#/Files//*[@size = '']

The above query will return all items from the Files folder in the media library. Your original query appears to be targeting content items, not the media library (assume this was just a incorrect example). The Template ID which you are targeting is also for Versioned JPEG, so also make sure your media items are of the above template type (I mention this since the default in Sitecore is to upload unversioned media).

  • Thanks for the answer. Its an SXA site and I believe that is a done thing in SXA to place media items in the content section beneath the site root. Strange thing I'm noticing now after seeing your tip about using the Size property is that many images are missing this, although the do have an image attached. Commented Jan 29, 2018 at 2:44
  • Interesting, SXA must add additional providers + locations for media. You could also try the query with *[@blob = ''] if you want to directly check the blob field.
    – jammykam
    Commented Jan 29, 2018 at 5:13
  • Oh yes, I did try `[@blob = ''] first, didn't notice I had pasted that nonsense query in the question! Commented Jan 29, 2018 at 8:39

I came across a situation in which I reserialized the items back to disk using Unicorn. The yaml contained all the properties but had an empty Value field for the base64 encoded media data. The following query helped me identity the busted items.

Example: The following finds items with a template type of File OR Image and validates that the blob id has a corresponding non-empty entry.

Import-Function -Name Invoke-SqlCommand

$connection = [Sitecore.Configuration.Settings]::GetConnectionString("master")

$query = @"
SELECT i.[ID], i.[Name]
FROM [dbo].[Items] i
    SELECT [ItemId], [Value]
    FROM dbo.SharedFields 
    WHERE [Value] != '' AND (FieldId='{40E50ED9-BA07-4702-992E-A912738D32DC}' OR FieldId='{DBBE7D99-1388-4357-BB34-AD71EDF18ED3}')
) sf
ON i.[ID] = sf.[ItemId]
WHERE i.[TemplateID] IN ('962b53c4-f93b-4df9-9821-415c867b8903', 'f1828a2c-7e5d-4bbd-98ca-320474871548')
AND sf.[Value] IS NULL AND i.[Name] != '__Standard Values'
$records = Invoke-SqlCommand -Connection $connection -Query $query
foreach($record in $records) {
    Get-Item -Path "master:" -ID $record.ID

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.