The IContentRepository has a method on it for deleting by reference
/// <summary>
/// Deletes a content from the repository first ensuring that the current user meets the minimal access right requirements.
/// </summary>
/// <param name="contentLink">The content link.</param>
/// <param name="forceDelete">If set to <c>true</c>, deletes the content even if it is being referenced by other content.</param>
/// <param name="access">The required access level that the current user must have to be allowed to delete the content.</param>
void Delete(ContentReference contentLink, bool forceDelete, AccessLevel access);
So just pass in the ContentReference and force delete true with access level of NoAccess and that should do the job. If you have problems consider looping through any children/depedants and delete first
So based on the IContentRepository being injected in the constructor and assiged to a class variable of _contentRepository
_contentRepository.Delete(reference, true, AccessLevel.NoAccess);
When you try to delete the page (and of course failed), is there anything error logged in the log?
Before proceeding to delete the page directly from the database, please note that it is generally not recommended to modify the database directly as it may lead to unexpected results and inconsistencies in the system. It is always advisable to have a backup of the database before performing any database operations.
With that said, here's a possible approach to deleting the page directly from the database:
Step#1
First, identify the Page ID of the page you want to delete. You can find this in the "tblPage" table in the database.
Step#2:
Check if there are any dependencies on the page. In Episerver, a page can have child pages, properties, or blocks that are linked to it. If you try to delete a page with dependencies, it will not allow you to do so. To check for dependencies, you can run the following SQL query:
SELECT COUNT(*) FROM tblProperty WHERE [fkPageID] = <page id>
If the count is greater than 0, it means that there are dependencies on the page. You need to delete these dependencies before proceeding.
Step#3:
If there are no dependencies, you can delete the page from the "tblPage" table by running the following SQL query:
DELETE FROM tblPage WHERE [PageID] = <page id>
Step#4:
Next, you need to clear the cache to ensure that the deleted page is no longer cached. You can do this by running the following SQL queries:
DELETE FROM tblCacheManager WHERE [ObjectId] = <page id>
DELETE FROM tblCacheDependency WHERE [ObjectId] = <page id>
Step#5:
Finally, clear the site's cache by deleting all the files in the "App_Data\EPiServer\Cache" folder.
After following these steps, the page should be deleted from the database, and any references to it should be cleared from the cache. However, please note that this approach may have unintended consequences and should be performed with caution.
Since the regular deletion process through the user interface is failing, and the page is not going to the trash, you're seeking a way to delete it directly from the database.
Given that you're using Episerver version 11 and are locally hosted, it's important to approach this task carefully. As an experienced SQL developer, you're already familiar with the basics, such as the Page ID and Language ID.
To delete the page and clean up any stuck status partials in the cache, you can try the following steps:
Begin by taking a backup of your database. This ensures that you have a safe copy before making any changes.
Use your SQL expertise to identify the relevant elements of the page in the database. Start by locating the table(s) that store page data. In Episerver, it could be something like "tblContent."
Once you've identified the appropriate table(s), construct a SQL script that targets the specific Page ID and Language ID associated with the page you want to delete. Make sure to include any other necessary identifiers you mentioned.
The SQL script should contain DELETE statements that remove the corresponding records from the identified table(s). Be cautious and double-check your script to ensure you're targeting the correct page and not inadvertently deleting unrelated data.
After executing the SQL script, verify that the page has been successfully removed from the database.
To clean up any stuck status partials in the cache, you may need to locate the cache storage mechanism used by your Episerver installation. This could involve finding relevant cache files or tables. Clearing or deleting these files/records should help remove any remnants of the problematic page.
Hello,
We have a page that is built automatically through the use of additional partials as children. This page has become extremely large, as the proces to clean up the page failed quietly some time ago. Now, when you try to delete the page through the UI, this fails to work; the activity icon flickers, but the action never completes, and the page does not go to the trash.
We need a way to delete this page directly from the database. Most scripts I have found for this date back to the Elektron days of the site. We are still locally hosted, not using the cloud hosting, the episerver version is 11.
I need to be able to delete the page and clean up any stuck status partials in the cache. I'm an experienced SQL developer, but identifying the various elements of the page in the DB has proven difficult. I know the Page ID, the Language ID, and other identifiers, I just need a complete script, or another suggestion as to how to get rid of this page.