4
votes

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"))
3

3 Answers

3
votes

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.

1
votes

Just a couple of additions to the excellent answer by @digbyswift (+1).

Umbraco occasionally references ids in the recycle bin, so sometimes deleted nodes that are 'appearing' are in the recycle bin - so emptying the recycle bin regularly does serve a purpose & will speed up node traversal in code.

If you use imagegen (most people do for images) then when a media image is rendered imagegen creates a cache version of the file - this can contain an old cached version of an old version of an image was referenced in one dimension (but not subsequently). You can safely remove any cache folders you are unsure of, if you are tidying up.

If after you've unreferenced for images from the content pages they were on you then delete the umbraco.config file, then Umbraco will rebuild it & you can be sure any rogue ids will be lost in the rebuild.

0
votes

Ok, after several hrs of head banging finally figured this out.

Turns out that little green button when you "save and publish" doesnt actually publish.

Making changes to the media folder doesnt actually work properly and seems to be out of sync.(dont quote me on that, just an observation).

Only way to resolve the issue is to "publish" the contents, Click on your content page, top right actions, should be a publish or "republish" option, click that and publish your content this seems to actually solve the issue.

I believe its a problem with the DB and Cache not syncing, and only syncing on a proper content publish.

Hopefully This will be explained in future documentation as it was a huge time sink on the developer end. Hope this helps guys!