SharePoint Add Datasheet View Programmatically

Hi,

Just a quick function to add Datasheet View when you're creating a document library or list programmatically:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
private void AddDataSheetView(SPList list)
{
    string viewName = "Datasheet View";
    //check if the view exist already, if not create it
    SPView datasheetView = null;
    try { datasheetView = list.Views[viewName]; }
    catch (System.ArgumentException e) { ;}
 
    if (datasheetView == null)
    {
        list.Views.Add(viewName, list.DefaultView.ViewFields.ToStringCollection(), null, 100, true, false, SPViewCollection.SPViewType.Grid, false);
        list.Views[viewName].Update();         
    }
}


HTH,
Andreas

Comments

Popular posts from this blog

SharePoint 2013 anonymous access add attachments to list item

CRM Plugin - Parent and Child Pipeline