使用控制台应用程序操作umbraco内容

本文关键字:umbraco 内容 操作 应用程序 控制台 | 更新日期: 2023-09-27 18:12:59

这是一个新手问题,但我搜索了一段时间,找不到任何有用的信息。

我需要开发一个程序(控制台应用程序),它将读取和写入内容到一个umbraco站点。我已经读到你可以用web表单和mvc应用程序做到这一点。

但是我需要像使用外部源一样使用umbraco。我需要像处理Word文档一样。例如:打开文件,读取文件,写一些东西并保存。

我已经安装了APIInstall-Package UmbracoCms -Pre

一些我已经读过的东西:http://nishantwork.wordpress.com/2012/09/27/umbraco-create-custom-content-node-in-umbraco-by-c/https://github.com/sitereactor/umbraco-console-example

实现这一目标的最佳方法是什么?我不知道该怎么做

使用控制台应用程序操作umbraco内容

您可以创建一个Umbraco节点(文档),从控制台应用程序写入并保存它。Umbraco基本上是一堆。net库:

//Get the type you would like to use by its alias and the user who should be the creator of the document 
DocumentType dt = DocumentType.GetByAlias("Textpage"); 
User author = User.GetUser(0); 
//create a document with a name, a type, an umbraco user, and the ID of the document's parent page. To create a document at the root of umbraco, use the id -1 
Document doc = Document.MakeNew("My new document", dt, author, 1018); 
// Get the properties you wish to modify by it's alias and set their value
doc.getProperty("bodyText").Value = "<p>Your body text</p>";
doc.getProperty("articleDate").Value = DateTime.Now;
//after creating the document, prepare it for publishing 
doc.Publish(author);
//Tell umbraco to publish the document
umbraco.library.UpdateDocumentCache(doc.Id);

:

http://our.umbraco.org/wiki/reference/api-cheatsheet/creating-a-documenthttp://our.umbraco.org/wiki/reference/api-cheatsheet/modifying-document-properties

只是为了帮助有同样问题的人。我在umbraco中找到了一个web服务,我目前正在使用它(直到现在仅用于读取信息,但据我所知,我们也可以编写信息)。虽然很少有文档,但很容易使用。但是要使用它,你需要在umbracoSettings中设置<webservices enabled="False">。配置。该文件位于umbraco中的Config文件夹中。我们还必须在webservices节点中设置用户权限,以允许用户使用web服务

DocumentServiceReference.documentServiceSoapClient client = new DocumentServiceReference.documentServiceSoapClient();
client.WebservicesEnabled();
DocumentServiceReference.ArrayOfDocumentCarrier documents = client.readList(parentId, username, password);
foreach (DocumentServiceReference.documentCarrier doc in documents)
{
    DocumentServiceReference.ArrayOfDocumentProperty properties = doc.DocumentProperties;
    foreach (DocumentServiceReference.documentProperty property in properties)
    {
        string key = property.Key;
        string value = property.PropertyValue.ToString();
    }
}