delete a page and its children
I need to delete a page and all its children. Right now I am not able to delete a pagenode.
With this code:
var manager = PageManager.GetManager();
var guidCourseToDelete = new Guid(ddlCourses.SelectedValue);
var pn = new PageNode("LessonBuilder1030/", guidCourseToDelete);
// at this point pn.Id is the correct value
manager.Delete(pn);
I get the following error. Please advise. Thanks
[InvalidOperationException: The instance is transient] DynamicModule.ns.Wrapped_OpenAccessPageProvider_dafc00828d0746a3be537e06dd250766.Delete(PageNode item) +249 Telerik.Sitefinity.Modules.Pages.PageManager.Delete(PageNode item) +181 LessonBuilder_UserControls_DeleteCourse.CmdDeleteCourse_Click(Object sender, EventArgs e) in c:\CurrentFiles\Projects\LessonBuilder1098\LessonBuilderApp\Sitefinity\LessonBuilder\UserControls\DeleteCourse.ascx.cs:39 System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBefo
Hello Phil,
I am a little bit unsure that the approach you are taking has correct logic. You are first creating a new node and then trying to delete it right away. If you do not want to store the page node you should just not call save changes (this will rollback transaction). In case that you wish to delete a page it is recommended that you use the Fluent API to get the corresponding page node you wish to delete and delete it:
public
void
DeletePage(
string
pageTitle)
App.WorkWith().Pages()
.Where(p => p.Page.Title == pageTitle)
.Delete()
.SaveChanges();