В следующем примере показано, как изменить порядок полей типа контента с помощью CSOM
var ctId = "0x01020047F5B07616CECD46AADA9B5B65CAFB75"; //Event ct
var listTitle = "Calendar";
using (var ctx = new ClientContext(webUri))
{
var list = ctx.Web.Lists.GetByTitle(listTitle);
var contentType = list.ContentTypes.GetById(ctId);
//retrieve fields
ctx.Load(contentType,ct => ct.FieldLinks);
ctx.ExecuteQuery();
var fieldNames = contentType.FieldLinks.ToList().Select(ct => ct.Name).ToArray();
fieldNames.ShiftElement(1, 2); //Ex.:Render Title after Location in Calendar
//reorder
contentType.FieldLinks.Reorder(fieldNames);
contentType.Update(false);
ctx.ExecuteQuery();
}
где
public static class ArrayExtensions
{
//from http://stackoverflow.com/a/7242944/1375553
public static void ShiftElement<T>(this T[] array, int oldIndex, int newIndex)
{
// TODO: Argument validation
if (oldIndex == newIndex)
{
return; // No-op
}
T tmp = array[oldIndex];
if (newIndex < oldIndex)
{
// Need to move part of the array "up" to make room
Array.Copy(array, newIndex, array, newIndex + 1, oldIndex - newIndex);
}
else
{
// Need to move part of the array "down" to fill the gap
Array.Copy(array, oldIndex + 1, array, oldIndex, newIndex - oldIndex);
}
array[newIndex] = tmp;
}
}
Результат
Перед
После
Вадим, спасибо за ответ! Я уже использовал этот способ (FieldLinkCollection.Reorder (string [])), но SharePoint.Client.ServerException, например, метод «Reorder» не существует. Этот метод существует в API Sharepoint 2010 или только в API Sharepoint 2013? – Nebiross