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 @ 21:31
    Khaled Alkasadi
    0

    For Better Performance Delete(media) Or MoveToRecycleBin(media)

    Hi to everyone ...
    to remove media from node and from Media 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 result of HasValue is true!! .. the error you will get is "Object reference not set to an instance of an object." .

    but when adding this line you will not get any errors :

    umbraco.library.RefreshContent();
    

    In other hand if i use MoveToRecycleBin() instead of Delete(), here we no need to use "umbraco.library.RefreshContent();" .

    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.


    Note : umbraco version is 6.2.4

    thanx ..

  • Alex Skrypnyk 6133 posts 23952 karma points MVP 7x admin c-trib
    Nov 20, 2014 @ 17:52
    Alex Skrypnyk
    0

    Hi Khaled,

    Try to use something like that:

    content.SetValue("image", null);
    

    "" - is just empty string value.

    Thanks

Please Sign in or register to post replies

Write your reply to:

Draft