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?
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?
i have the same problem, did you find a way to solve it?
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!
:)
now im sorry i already did wote MVP lol...
but i will take a look at it and see if it solves my problem ;-)
Tim, can you tell me the best way to hook up application_start in the latest umbraco version?
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!
Cool, thanks ;-)
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 :)
is working on a reply...