我正在嘗試使用sitecore API來序列化和還原sitecore項目。我創建了一個WCF應用程序來檢索給定ID或sitecore路徑(/ sitecore/content/home)的項目名稱,檢索子項給出id或路徑的項目名稱列表。我也可以序列化內容樹。如何使用Sitecore.Data.Serialization.Manager.LoadItem(path,LoadOptions)將項目恢復到Sitecore?
public void BackupItemTree(string id)
{
Database db = Sitecore.Configuration.Factory.GetDatabase("master");
Item itm = db.GetItem(id);
Sitecore.Data.Serialization.Manager.DumpTree(itm);
}
上面的代碼很好用。運行後可以看到內容樹已被序列化。
然而,當我試圖還原序列化項目期運用如下:
public void RestoreItemTree(string path)
{
try
{
using (new Sitecore.SecurityModel.SecurityDisabler())
{
Database db = Sitecore.Configuration.Factory.GetDatabase("master");
Data.Serialization.LoadOptions opt = new Data.Serialization.LoadOptions(db);
opt.ForceUpdate = true;
Sitecore.Data.Serialization.Manager.LoadItem(path, opt);
//Sitecore.Data.Serialization.Manager.LoadTree(path, opt);
}
}
catch (Exception ex)
{
throw ex;
}
}
有了這個代碼,我沒有得到任何錯誤。它運行,但如果我檢查SiteCore它沒有做任何事情。我已經使用Office Core示例進行了測試。我發送的路徑可能是這樣的:
C:\ inetpub \ wwwroot \ sitecoretest \ Data \ serialization \ master \ sitecore \ content \ Home \ Standard-Items \ Teasers \ Our-Clients.item
和
C:\的Inetpub \ wwwroot的\ sitecorebfahnestockinet \ DATA \序列\主\ Sitecore的\內容\首頁\標準項\ \玩笑我們的客戶端
似乎都不做任何事情。我改變了該項目的預告片標題,並試圖在每次改變仍然存在之前恢復。
任何幫助將不勝感激,因爲SiteCore文檔是非常有限的。
感謝您的評論,我會看看。 –
我已經使用這兩個帖子的信息,但仍然沒有進展。最終使用ItemReference對象最終給我一樣的:我以前使用的C:\ inetpub \ wwwroot \ sitecoretest \ Data \ serialization \ master \ sitecore \ content \ Home \ Standard-Items \ Teasers \ Our-Clients.item路徑。不過,我仍然看不到SiteCore內的變化,仍然沒有錯誤。所以我有更簡潔的代碼,但沒有解決方案。 –
我測試了所提供的功能,並且能夠恢復項目。步驟:1.序列化你/ sitecore/content/home項目。 2.更改該項目的一個字段。 3.用「/ sitecore/content/home」路徑調用該方法。 –