What is the proper way to move page to recycle bin and delete page progammatically?

Vote:
 

Question 1: move content to waste basket

I tested IContentRepository.MoveToWastebasket() funtion, but when I tried to restore the content from the recycle bin, it showed: "The original place for the content does not exist. Where would you like to restore the content?" and ask me to choose a location to restore the content to.

However this doesn't satisfy the demand, the content are moved to waste basket in batches, and some of them might need to be restored to it's original place. Is there a better way to move content to recycle bin prgrammatically?

Question 2: delete content

I also need to delete content progammatically, the functions I use is IContentRepository.Delete() and IContentRepository.DeleteChildren(). However, after I used these functions, the full text search index started to act abnormally, new content cannot be indexed and the reindex function doesn't work anymore.

I am using EPiServer 8.11.0, is there a better API I should use here?

#143763
Jan 29, 2016 16:41
Vote:
 

1. I think you are using the correct function. Might be you have also deleted the parent page to the one you are trying to restore 

2. Might be a bug. Try first sending items to wastebasket and then delete them? To get all events triggered...

#144494
Feb 14, 2016 10:45
Vote:
 

When I try to move items to waste basket using MoveToWastebasket method, I get an exception saying that Delete permission is required when a scheduled job is run automatically. At the same time it works ok if I start the job manually. How do I get it work for a scheduled job?

#170815
Edited, Oct 31, 2016 11:25
Vote:
 

When running automatically you run as anonymous user that lacks those access rights. 

1. Create a new system user that has delete access rights at least. 

2. Run scheduled job as that user

PrincipalInfo.CurrentPrincipal = PrincipalInfo.CreatePrincipal("your.username");
#170936
Oct 31, 2016 13:33
Vote:
 
DataFactory.Instance.MoveToWastebasket(page.ContentLink);
#190275
Apr 06, 2018 15:44
Vote:
 

However, after I used these functions, the full text search index started to act abnormally, new content cannot be indexed and the reindex function doesn't work anymore.

This could be because the content you're deleting is referenced on some other content. When this other content would be indexed it would crash the indexing because one of it's references is  missing.

Normally when you remove a page from the UI you get a prompt like this:

Move to trash

So through there this isn't necessarily an issue, but programatically it doesn't prompt. It just deletes the content.

You can solve this if you run 

var referencesToPage = ContentRepository.GetReferencesToContent(pageToRemove.ContentLink, true/false); // last parameter can be true if you want to get content that references any of the "pageToRemove"s children as well.

before deleting you can see how that content is referenced, then you could delete the references based on the data you get out of that method call.

Hope this helps!

#190282
Apr 06, 2018 20:16
Vote:
 

However, after I used these functions, the full text search index started to act abnormally, new content cannot be indexed and the reindex function doesn't work anymore.

This could be because the content you're deleting is referenced on some other content. When this other content would be indexed it would crash the indexing because one of it's references is  missing.

Normally when you remove a page from the UI you get a prompt like this:

Move to trash

So through there this isn't necessarily an issue, but programatically it doesn't prompt. It just deletes the content.

You can solve this if you run 

var referencesToPage = ContentRepository.GetReferencesToContent(pageToRemove.ContentLink, true/false); // last parameter can be true if you want to get content that references any of the "pageToRemove"s children as well.

before deleting you can see how that content is referenced, then you could delete the references based on the data you get out of that method call.

Hope this helps!

#190283
Apr 06, 2018 20:16
Vote:
 

This could be because the content you're deleting is referenced on some other content. When this other content would be indexed it would crash the indexing because one of it's references is  missing.

Normally when you remove a page from the UI you get a prompt like this:

Move to Trash Image

So through there this isn't necessarily an issue, but programatically it doesn't prompt. It just deletes the content.

You can solve this if you call this method before deleting:

var referencesToPage = ContentRepository.GetReferencesToContent(pageToRemove.ContentLink, true/false); // last parameter can be true if you want to get content that references any of the "pageToRemove"s children as well.

From there you can see how that content is referenced, then you could delete the references based on the data you get out of that method call.

Hope this helps!

#190284
Edited, Apr 06, 2018 20:16
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.