2013-05-10 63 views
3

这是一个noob问题,但我正在寻找一些时间,并且找不到任何有用的信息。使用控制台应用程序操纵umbraco内容

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

但我需要使用像外部源的umbraco。我需要像处理Word文档那样做一些事情。例如:打开文件,读取文件,写入一些内容并保存。

我已经安装使用 PM的API>安装,包装UmbracoCms - 预

有些事情我已经阅读: http://nishantwork.wordpress.com/2012/09/27/umbraco-create-custom-content-node-in-umbraco-by-c/ https://github.com/sitereactor/umbraco-console-example

什么是最好的实现呢?我不知道该怎么做...

回答

1

只是为了帮助别人用同样的问题。我在umbraco中找到了一个web服务,我目前正在使用它(直到现在只用于阅读信息,但据我所知我们也可以写信息)。 Altought很少有文档易于使用。 但要使用它,你需要在umbracoSettings.config中设置<webservices enabled="False">。这个名字在umbraco里面的Config文件夹里。 我们要设置用户权限到web服务节点还允许用户使用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(); 
    } 
} 
3

您可以创建一个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-document http://our.umbraco.org/wiki/reference/api-cheatsheet/modifying-document-properties

+0

感谢您的帮助,但我已经决定用一把umbraco Web服务。 – Thiago 2013-05-20 13:23:13

+1

没问题。但请谨慎行事,并参阅最近推荐的Umbraco安全简报http://umbraco.com/follow-us/blog-archive/2013/4/29/security-vulnerability-found-immediate-action-recommended.aspx。删除的Web服务的DLL。 – amelvin 2013-05-21 09:44:47

+0

@amelvin您确定此代码在控制台应用程序内部工作吗?我面临这个问题 - http://stackoverflow.com/questions/20358594/umbraco-try-to-read-document-properties-programatically-but-always-getting-nul?noredirect=1#comment30393355_20358594 – Suhas 2013-12-04 10:24:24