1

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?

1

We cannot assign the personal view to specific user directly in SharePoint.

There is a workaround.

We can get the user who logins the SharePoint site. And then redirect to different view according to the different users who login the SharePoint site.

More reference:

How to Get the Current User's Properties Using CSOM in SharePoint 2013.

  • And Is it possible to retrieve data about whom this view is belonged to via csom ? Or how i can find this info in WSS_Content database directly. – isxaker Mar 15 '18 at 14:54
1

for me the easiest workaround is adding a "Users View" Column

i would add to that column all the people i want to give access to that view and on the view filter i would set the filter by [Me]

then i would remove that field from the view so no one can create another view

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.