locked
List views of type Datasheet created in CSOM do not appear in the list's 'view selector' RRS feed

  • Question

  • Hi,

    As the title suggests, I am setting up some datasheet/grid views through a script in the client side object model (C#). The problem is that the users are unable to select the views in the list web part. Standard views created in CSOM appear, as well as datasheet views created manually in sharepoint.

    The views are available in the list settings, so I know they are attached to the list.

    How can I make the views created in CSOM appear in the web part just like manually created views do?

    Best regards,

    Joachim

    Wednesday, August 19, 2015 12:56 PM

All replies

  • Hi Joachim,

    I would suggest you try the code below in your environment to see if it will work for you:

    public static void createView()
    { 
        string siteUrl = "http://sp";
    
        ClientContext clientContext = new ClientContext(siteUrl);
        List oList = clientContext.Web.Lists.GetByTitle("LS810317");
    
        clientContext.Load(oList);
        clientContext.ExecuteQuery();
    
        ViewCreationInformation viewCreationInformation = new ViewCreationInformation();
        viewCreationInformation.Title = "mdsv1";
        viewCreationInformation.ViewTypeKind = ViewType.Grid;
        viewCreationInformation.RowLimit = 30;
    
        //Make sure that the name of the fields should be equal to 1 any of the associated SiteColumns Internal Name. The Fields in the view will appear in the same order as declared here.
        viewCreationInformation.ViewFields = new string[]{"Title","Created","Modified"};
        viewCreationInformation.SetAsDefaultView = true;
    
        oList.Views.Add(viewCreationInformation);
    
        clientContext.Load(oList.Views);
        clientContext.ExecuteQuery();
    
        Console.WriteLine(oList.Views.Count);
    }

    This is the outcome after I executed the code in my environment:

    Feel free to reply if there any progress.

    Thanks 

    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    Thursday, August 20, 2015 8:28 AM
  • Hi Patrick and thank you for replying,

    It might not have been clear in my original post, but I am able to add the view to the list so that it is visible in the 'Current View' drop down as well as in the list settings. The problem is that it doesn't appear in the view menu of the list view web part below (only when selected as default of which I can only have one). The code I am using is very similar to the one you posted.

    Thanks,

    Joachim

    Thursday, August 20, 2015 10:32 AM
  • Hi Joachim, did you find a resolution to this issue? I'm having the same problem. Thanks.
    Wednesday, December 9, 2015 3:22 PM
  • we need a solution for this!


    "The more difficult something became, the more rewardant it was in the end"
    http://ftduarte.blogspot.com

    Sunday, September 18, 2016 12:09 PM
  • I just ran into exactly the same problem in O365 using PowerShell and CSOM using ViewType of Grid. Did this ever get solved? Any idea as to the view property that needs to be set? Any suggestions are appreciated. Thanks ~B

    Barry Noble

    Tuesday, September 12, 2017 3:50 PM
  • yep.

    I finally found out why.

    this is described in SE post,

    https://sharepoint.stackexchange.com/questions/193127/datasheet-view-added-programatically-missing-from-view-selector

    basically the issue is not in the view, but in the webpart for each of the OTHER views in the list that fail to show views of type grid.

    the solution is to go to each view and tweak the webpart checkbox "disable view selector menu", which can also bea achieved programatically


    "The more difficult something became, the more rewardant it was in the end"
    http://ftduarte.blogspot.com


    • Edited by ftduarte Tuesday, September 12, 2017 3:56 PM
    Tuesday, September 12, 2017 3:55 PM
  • Hi:

    You put me on the right track. Instead of editing the web parts, I opened the site in SPD went to the list, opened the 'missing' view page I had created in PS/CSOM, and did nothing except to click the save icon. Bada Boom the 'missing' view appears on all page view menu of the web parts and in the SP ribbon in Manage Views. 

    What a hack! 

    Since I'm creating several views on a list that occurs 100+ times I'm now going to try the PS example you pointed me to. Don't want to wear my fingers to the bone in SPD. Although I'm still going to have to fix up the views as they are over a task and the WP is displaying the timeline. 

    Thanks much. You saved me a lot of trial and error as I thought for sure it was a view property I was not setting. 

    Regards, 

    ~B


    Barry Noble

    Tuesday, September 12, 2017 5:49 PM