Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Khaled Alkasadi 2 posts 22 karma points
    Nov 19, 2014 @ 14:43
    Khaled Alkasadi
    0

    Delete(media) Vs MoveToRecycleBin(media)

    when i use

    mediaService.Delete(media , 0);
    content.SetValue("image", "");
    contentService.SaveAndPublish(content, userId: 0);
    

    it seems like ok, but you will get error here :

    string img = Model.HasValue("image") ? Model.MediaById(Model.GetProperty("image")).Value).umbracoFile : "";
    

    the error is "Object reference not set to an instance of an object."

    but when you add this line it will not get any errors

    umbraco.library.RefreshContent();
    

    but if i use MoveToRecycleBin() instead of Delete(), here we no need to use refreshContent(), will not get any errors.

    mediaService.MoveToRecycleBin(media , 0);
    content.SetValue("image", "");
    contentService.SaveAndPublish(content, userId: 0);
    

    so the Delete(media) should use refrechContent(), but MoveToRecycleBin(media) no need to use refrechContent().

    for a good performance:
    - which one is better to delete image.
    - and should i use refreshContent() when updating content

    thanx

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Nov 20, 2014 @ 17:56
    Alex Skrypnyk
    0

    Hi Khaled,

    Try to use something like that:

    content.SetValue("image", null);
    

    "" - is empty string value.

    Thanks

  • Charles Afford 1163 posts 1709 karma points
    Nov 20, 2014 @ 23:42
    Charles Afford
    0

    Kahled,

    That sort of makes sense although i dont of the top of my head know what is happening under the covers.

    Delete is removing the piece of media, therefore when you try to instance it, its returning null

    MoveToRecycleBin() is moving the media to the recycle bin and therefore when you try to instance it it is being returned as an object of type Media / IMedia (what ever the type is). If you inspect the object. I think it has a property of IsTrashed something like that that will be set to true :).

    Thanks,

    Charlie.

Please Sign in or register to post replies

Write your reply to:

Draft