Search code examples
c#visual-studio-2012.net-4.5umbraco

Umbraco 7.1.4 Media Manager, Id exists after Deletion


I am using visual studio 2012, C#/net 4.5, Umbraco 7.1.4.

Got an issue with the media folder.

I deleted the images and folders in the media folder via the CMS.

However when I did this the content pages were still attempting to find and use these images.

So I removed any links from all the media pickers.

Still had the issue, so I checked my code, and its still looking for the file.

So this time i looked around and removed from the Recycle bin. Still trying to find the ID.

So then i looked through the Folder itself on window explorer, files were all there.....strange. so i deleted all of them. Guess what? still trying to search for the media. i checked my solution explorer, Yeh you guessed it there still in there! so i deleted it from there too.

So, deleted all media files, deleted all references, deleted all images in folders.

there should be no references, no images.

but guess what, I step through the following code, and somewhere in Umbraco it still has the ID of the images.

@if (Model.Content.GetPropertyValue("logo") != null)
{
    var mediaItem = Umbraco.TypedMedia(Model.Content.GetPropertyValue("logo", true));
    <img class="img-logo" src="@mediaItem.GetPropertyValue("umbracoFile")" width="100" height="50" alt=""/>
}

Can someone please tell me what is going on?

Additional information:

I published my website and ftped it over to my dev server, the DB did not move as my local copy and the dev copy now point to the same DB. This was a test to see if the publish would work.

when I used the site though none of the images where showing, although the images were there in the folders. I looked around and found it weird. So i decided to remove all images and references, 1st I deleted all folders in the cms. then I removed all references from the content. The rest as I said is all explained, no matter what I do its still trying to find these damn Images.

Any help would be amazing as I'm completely stuck.

Also: should mention that

@if (Model.Content.GetPropertyValue("logo") != null)

was originally

@if (Model.Content.HasValue("logo"))

Solution

  • This can be a little confusing but I may be able to help you here.

    When you save an image it doesn't publish it in the same way that content is published. The information about an image written to the database and also indexed by Examine. Any requests for images by the UI hit the Examine index, not the database and not the XML cache.

    When an image is deleted in the CMS (and subsequently deleted from the recycle bin), the physical image is retained on the file system but the record is removed from the database. It is also removed from the Examine index.

    However, when an image is referenced by content, that reference is recorded in the database and if published is recorded in the site XML cache. If you then delete the image from the CMS, the content will still reference the image and as you saw for yourself could not find it. If you un-reference the image, you still have to publish the content to remove the reference from the XML cache.

    The best approach in this situation is to un-reference your imagery first, republish your content, then lastly delete the image(s).

    With regards to the files still showing in Visual Studio after being deleted, this is because the .csproj file retains references to the files. If you delete the files from the OS, the file references will not be removed from the .csproj file. Again best practice is to delete from the project from within Visual Studio.

    Hope this helps. I know it seems like this was an issue with Umbraco, but everything you experienced is actually the way it is supposed to be.