コードビハインドを使用してサイトコアにアイテムを作成したい。
私はこのコードを見つけました、そしてそれは完全にうまく働きます。
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つのことをどのように組み合わせるのかわかりません。
2つの方法を考えます。
方法1
私が作成したID
のをつかみます。Item
私はつかむことName
がName
できますが、重複している可能性があります。
方法2
作成する前にフィールドに入力してくださいItem
しかし、それでは..繰り返しますが、これら2つの方法を実行する方法がわかりません。
ヒントをいただければ幸いです。
前もって感謝します。