我有下一个代码(就像原型一样)
private void WriteDataToItems(Item rootitem, IQueryable<LanguageData> languageData, SC.Globalization.Language sclng)
{
if (rootitem == null)
return;
rootitem = IncVersion(rootitem);
Response.Write(string.Format("Item {0} - {1}<br/>", rootitem.DisplayName, rootitem.Paths.FullPath));
rootitem.Editing.BeginEdit();
try
{
foreach (Field fld in rootitem.Fields.Where(d => !d.Shared && !d.Name.StartsWith("__") && d.Name.Trim() != ""))
{
Response.Write(string.Format("Processing fld: - {0}<br/>", fld.ID.Guid.ToString()));
var data = languageData.FirstOrDefault(
d => (string.Compare(d.FieldName, fld.Name, true) == 0) && (string.Compare(d.ItemID, rootitem.ID.Guid.ToString(), true) == 0));
if (data != null)
{
string newValue = null;
switch (sclng.Name)
{
case "en":
newValue = data.En;
break;
case "nn-NO":
newValue = data.nnNO;
break;
case "sv-SE":
newValue = data.svSE;
break;
case "da-DK":
newValue = data.DaDK;
break;
case "de-DE":
newValue = data.deDE;
break;
default:
newValue = null;
break;
}
if (newValue != null)
{
Response.Write(string.Format("Save field with Id:{0} New Value:{1}<br/>", fld.ID.Guid, newValue));
fld.Value = newValue;
}
}
}
rootitem.Editing.EndEdit();
}
catch (Exception ex)
{
rootitem.Editing.CancelEdit();
}
foreach (Item cd in rootitem.GetChildren())
{
WriteDataToItems(cd, languageData, sclng);
}
}
以及rootitem.Fields对象不包含模板中描述的所有字段的问题,我只是有一个文件,它只包含具有某些值但不包含具有空数据的字段的字段
foreach (Field fld in rootitem.Fields.Where(d => !d.Shared && !d.Name.StartsWith("__") && d.Name.Trim() != ""))
如何获取所有自定义字段名称?我应该使用模板数据吗?