Copied to clipboard

Flag this post as spam?

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


  • greengiant83 88 posts 109 karma points
    Feb 17, 2011 @ 23:26
    greengiant83
    0

    How to delete document

    What is the proper way to delete a document?  I have it like this:

                Document doc = new Document(Model.Id);

                doc.delete();

     

                umbraco.library.UpdateDocumentCache(doc.Id);

                umbraco.library.RefreshContent();

                Response.Redirect(Request.RawUrl);

    My problem is that the when the page reloads (coming back from the redirect) that the item is still found.  If I refresh a second time it show as deleted as intended.  I am using the Linq to Umbraco datacontext to do the search:

    Model = SiteDataContext.Instance.PersonalFundraisers.FirstOrDefault(i => i.Member.HasValue && i.Member.Value == Member.CurrentMemberId());

    As you can see I have an Instance member tacked onto the datacontext as a pseudo singleton implementation (let me know if this isnt a good idea to do, btw).  The instance is just stored the for the life of one request in the HttpContext's Items collection:

     

            public static SiteDataContext Instance

            {

                get

                {

                    var context = HttpContext.Current.Items["SiteDataContext"] as SiteDataContext;

                    if (context == null) HttpContext.Current.Items["SiteDataContext"] = context = new SiteDataContext();

                    return context;

                }

            }

     

    How can I get the deletion to be reflected immediately instead of having to do a second refresh?

  • kows 81 posts 151 karma points c-trib
    Feb 18, 2011 @ 10:13
    kows
    0
    Maybe try to add AfterMoveToTrash or AfterDelete handler to the document before delete & try the redirect in there?
  • Amigo 243 posts 568 karma points
    Mar 15, 2011 @ 10:15
    Amigo
    0

    i have the same problem, did you find a way to solve it?

  • Tim 1193 posts 2675 karma points MVP 3x c-trib
    Mar 15, 2011 @ 17:27
    Tim
    0

    This person had a similar problem with the context not being updated straight away, see his last post for his solution:

    http://our.umbraco.org/forum/using/ui-questions/18215-unpublished-items-stay-until-webconfig-touched

    Hope that helps!

    :)

  • Amigo 243 posts 568 karma points
    Mar 15, 2011 @ 18:15
    Amigo
    0

    now im sorry i already did wote MVP lol...
    but i will take a look at it and see if it solves my problem ;-)

  • Amigo 243 posts 568 karma points
    Mar 15, 2011 @ 18:38
    Amigo
    0

    Tim, can you tell me the best way to hook up application_start in the latest umbraco version?

  • Tim 1193 posts 2675 karma points MVP 3x c-trib
    Mar 16, 2011 @ 10:10
    Tim
    1

    If you want to hook into the Application_Start event like you would in the global.asax file, you could create an HTTP Module (see the answer on this stack overflow post: http://stackoverflow.com/questions/2779137/hook-into-application-start-in-a-httpmodule)

    The other method is to use the Umbraco ApplicationBase class, details here:

    http://our.umbraco.org/wiki/reference/api-cheatsheet/using-applicationbase-to-register-events

    Put your startup event in the default method for your class and it should get run on the application start!

  • Amigo 243 posts 568 karma points
    Mar 16, 2011 @ 13:23
    Amigo
    0

    Cool, thanks ;-)

  • Mysterious 27 posts 47 karma points
    Mar 10, 2012 @ 12:09
    Mysterious
    0

    Hello,

    In case anybody wondering how to do it in Razor:

    this is a full workable script, the script is expecting the node id in the parameter "PhotoNodeID"

    enjoy :)

    @using umbraco.cms.businesslogic.web
    @using umbraco.MacroEngines
    @inherits umbraco.MacroEngines.DynamicNodeContext
    
    @{    
        if (!String.IsNullOrEmpty(@Parameter.PhotoNodeID) &&
            umbraco.library.IsLoggedOn()&&
            System.Web.Security.Roles.IsUserInRole("Administrators"))
        {
            int docid=0;
            if (int.TryParse(@Parameter.PhotoNodeID.ToString(),out docid))
            { 
                Document doc = new Document(docid);
                if (doc != null)
                { 
                    doc.UnPublish();
                    doc.delete(true);
                    umbraco.library.RefreshContent();
                }
            }
        }
    
        Response.Redirect("/");
    }
Please Sign in or register to post replies

Write your reply to:

Draft