2013-05-10 35 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