Question

I've written a web service call that dynamically creates pages based upon the response from a web service every 60 seconds. The service I am using is a simple weather forecast service that gives a 7 day forecast of the weather in a specific region. All of the new content nodes are created using the following:

var weather = cs.CreateContent("Weather Forecast " + forecast.Date, rootID, "weather");  // Where rootID is the homepage of the site

As I'm ultimately going to adapt this web service call to only display one set of results (the most recent set) I wish to try and delete the content based upon the document type. Is this possible? From what I have seen here: http://our.umbraco.org/documentation/reference/Management-v6/Services/ContentService it is not but there must be a workaround so that I can bulk delete the old content created from the web service call and replace it with the most recent content.

I thought doing something like this would be possible:

cs.GetChildren(rootID).Where(x => x.DocumentTypeAlias == "weather" );

But according to my Visual Studio this appears to be invalid.

Any help would be greatly appreciated.

/Jason

Was it helpful?

Solution

This is entirely possible using the following syntax:

var weatherPages = cs.GetChildren(rootID).Where(x => x.ContentType.Alias == "weather");

Each of the matching pages can then be deleted using the following syntax:

foreach (var item in weatherPages){
  cs.Delete(item);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top