sharepointcsom

SharePoint List, help deleting the Title field or remove from defaultview?- using CSOM


Using CSOM for SharePoint Online Site Collection, able to create lists, edit lists items, add list items, etc. Just can not figure out how to either delete the 'Title' field or just remove it from the default view. At least got it to not be required. Found a few examples with Google but none worked. Any sample code or link to good source. Following is one of the versions attempted. We're stuck using VB Net (corporate direction) but C# sample would help too.

Side question; we currently using CSOM within VB Net to interact with SP on the client side, what are opinions on using PowerShell or PnP or maybe REST API instead? We are permitted to use other languages if the're interpreted languages. Any advantages of any over others? Are any outdated per se?

        Using clientContext As New Microsoft.SharePoint.Client.ClientContext(siteUrl)
            clientContext.Credentials = credentials
            Dim oWebsite As Microsoft.SharePoint.Client.Web = clientContext.Web
            Dim oList As Microsoft.SharePoint.Client.List = oWebsite.GetListByTitle(listName)
            Dim oView As Microsoft.SharePoint.Client.View = oList.DefaultView
            clientContext.Load(oView, Function(vw) vw.ViewFields)
            Dim ofield As Microsoft.SharePoint.Client.Field = oList.Fields.GetByInternalNameOrTitle("Title")
            Dim ofieldNumber As Microsoft.SharePoint.Client.FieldNumber = clientContext.CastTo(Of Microsoft.SharePoint.Client.FieldNumber)(ofield)
            clientContext.Load(ofieldNumber)
            clientContext.ExecuteQuery()
            oView.ViewFields.Remove("Title")
            oView.Update()
            clientContext.ExecuteQuery()
        End Using

Thank you in advance for any responses.


Solution

  • By default, the 'Title' field in a view is named "LinkTitle".

     oView.ViewFields.Remove("LinkTitle")