本文整理汇总了C#中IItem.AddFromTemplate方法的典型用法代码示例。如果您正苦于以下问题:C# IItem.AddFromTemplate方法的具体用法?C# IItem.AddFromTemplate怎么用?C# IItem.AddFromTemplate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IItem
的用法示例。
在下文中一共展示了IItem.AddFromTemplate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CopyItemCallback
public void CopyItemCallback(IItem sourceItem, IItem destinationParentItem, IItem destinationItem)
{
if (_PluginOptions[0].Value == "False")
return;
foreach (IItem sourceTemplate in sourceItem.Templates)
{
// Check if the correct template exists on the item
if (sourceTemplate.Name.ToLower() != _PluginOptions[3].Value.ToLower())
continue;
IField field = Util.GetFieldByName("__publish", destinationItem.Fields);
if (field == null)
{
field = Util.GetFieldByName("__valid to", destinationItem.Fields);
if (field == null)
{
field = Util.GetFieldByName("__created", destinationItem.Fields);
}
}
if (field == null)
throw new Exception("Error finding any valid date field in " + this.Name + " plugin.");
DateTime date = Util.XsdDatetimeToDateTime(field.Content);
string sDate = date.ToString(_PluginOptions[1].Value);
string sYearPath = destinationParentItem.Path + "/" + sDate;
IItem yearFolder = destinationParentItem.GetItem(sYearPath);
if (yearFolder == null)
{
string sFolderID = destinationParentItem.AddFromTemplate(sDate, "/sitecore/templates/common/folder");
yearFolder = destinationItem.GetItem(sFolderID);
}
bool bResult = false;
if (_PluginOptions[2].Value == "")
bResult = destinationItem.MoveTo(yearFolder);
else
{
string sMonth = date.ToString(_PluginOptions[2].Value);
IItem monthFolder = destinationParentItem.GetItem(sYearPath + "/" + sMonth);
if (monthFolder == null)
{
string sFolderID = yearFolder.AddFromTemplate(sMonth, "/sitecore/templates/common/folder");
monthFolder = destinationItem.GetItem(sFolderID);
monthFolder.SortOrder = date.ToString("MM");
monthFolder.Save();
}
destinationItem.MoveTo(monthFolder);
}
}
}