我想使用后面的代码创建一个项目到sitecore。Sitecore创建包含字段[]的项目
我发现这段代码,它工作得很好。
public void CreateItem(String itmName)
{
//Again we need to handle security
//In this example we just disable it
using (new SecurityDisabler())
{
//First get the parent item from the master database
Database masterDb = Sitecore.Configuration.Factory.GetDatabase("master");
Item parentItem = masterDb.Items["/sitecore/content/SOHO/Settings/Metadata/Project"];
//Now we need to get the template from which the item is created
TemplateItem template = masterDb.GetTemplate("SOHO/Misc/Project");
//Now we can add the new item as a child to the parent
parentItem.Add(itmName, template);
//We can now manipulate the fields and publish as in the previous example
}
}
但我想填写的领域也。如..
Item.Fields["test"].Value="testing";
对于我发现了如何编辑项目
public void AlterItem()
{
//Use a security disabler to allow changes
using (new Sitecore.SecurityModel.SecurityDisabler())
{
//You want to alter the item in the master database, so get the item from there
Database db = Sitecore.Configuration.Factory.GetDatabase("master");
Item item = db.Items["/sitecore/content/home"];
//Begin editing
item.Editing.BeginEdit();
try
{
//perform the editing
item.Fields["Title"].Value = "This value will be stored";
}
finally
{
//Close the editing state
item.Editing.EndEdit();
}
}
}
但我不知道如何将这些两件事情结合起来。
我想到了2种方法。
方法1
抢,我创建了Item
的ID
。
我可以抓住Name
,但Name
可能会被复制。
方法2
在字段中填写创建Item
之前,但随后再次..我不知道如何做那些2种方法。
如果我能得到一些提示,我将不胜感激。
在此先感谢。
可能值得一提的是,良好的做法通常是使用项目ID而不是路径。这样你的代码就不依赖于内容树中的IA。我觉得一般的性能也更好地使用本机的ID – geedubb