Usually I create view using ViewCreationInformation class:
public static void Create(this ViewCollection viewCollection, IListView view, string desiredTitle, ContentTypeId contentTypeId)
{
//create
var viewCreationInfo = view.ToViewCreationInformation();
//mark for futher process
viewCreationInfo.Title = view.SystemTitle;
//upload to server
viewCollection.Add(viewCreationInfo);
viewCollection.Context.ExecuteQuery();
var createdView = viewCollection.GetByTitle(view.SystemTitle);
createdView.LoadAndExecute(c=>c.ViewType, c=>c.PersonalView);
//update
createdView.UpdateAggregations(view);
createdView.Title = desiredTitle;
createdView.ContentTypeId = contentTypeId;
createdView.ViewData = view.ViewData;
ViewType viewType;
if (!createdView.PersonalView && Enum.TryParse(createdView.ViewType, true, out viewType) && viewType == ViewType.Html)
{
createdView.MobileDefaultView = view.IsMobileDefaultView();
createdView.MobileView = view.IsMobileView();
}
//save
createdView.Update();
viewCollection.Context.ExecuteQuery();
}
public static ViewCreationInformation ToViewCreationInformation(this IListView listView)
{
return new ViewCreationInformation
{
Query = listView.Query,
Paged = listView.IsPaged,
RowLimit = Convert.ToUInt32(listView.RowLimit),
SetAsDefaultView = listView.IsDefault,
ViewFields = listView.Fields?.ToArray(),
ViewTypeKind = listView.GetViewType(),
PersonalView = listView.IsPersonalView()
};
}
public static void UpdateAggregations(this View spView, IListView veeamView)
{
//!!!The order of assigning is VERY IMPORTANT here
//it's just a SP
spView.Aggregations = veeamView.Aggregations;
spView.AggregationsStatus = veeamView.AggregationsStatus.ToString();
}
But I have a problem there. I have no idea how to specify that a specific personal view belongs to a specific user. Any ideas?