[英]Deleting content based upon document type using the Umbraco content service
I've written a web service call that dynamically creates pages based upon the response from a web service every 60 seconds. 我编写了一个Web服务调用,该调用每60秒根据来自Web服务的响应动态创建页面。 The service I am using is a simple weather forecast service that gives a 7 day forecast of the weather in a specific region.
我正在使用的服务是一个简单的天气预报服务,可以提供特定地区7天的天气预报。 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. 由于我最终将使该Web服务调用适应于仅显示一组结果(最近的一组),因此我希望尝试根据文档类型删除内容。 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.
从我在这里看到的内容来看: http : //our.umbraco.org/documentation/reference/Management-v6/Services/ContentService不是,但是必须有一种解决方法,以便我可以批量删除从Web创建的旧内容服务电话并将其替换为最新内容。
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. 但是根据我的Visual Studio,这似乎是无效的。
Any help would be greatly appreciated. 任何帮助将不胜感激。
/Jason /杰森
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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.