Programatically define document set default view
-
08-02-2021 - |
Вопрос
Im trying to be define a document set default view from powershell, code, csom, or site template, but I cant find any way to do so.
My library have 5 views, and I have a document set XX added to the available content types for the library. I have this document set to have as default list view the view YY from the library, any ideas?
Решение
After a long research, I can confirm that this seems to be only doable on a sharepoint on premises environment. Sharepoint online CSOM doesnt allow to change the schemaxml of the contentype by CSOM, neither by site template.
On a onpremises env, you can modify the contentypes wihtin a list, modifying the schemaxm, following this example:
[once connected to a site]
$site_csom = Get-PnPContext
$web= $site_csom.Web
$list = $site_csom.Web.Lists.GetByTitle("mylist")
$site_csom.Load($web)
$site_csom.Load($list)
$site_csom.Load($list.ContentTypes)
$site_csom.ExecuteQuery()
$list.ContentTypes[1].SchemaXml= [your new xml definition for the contentype]
$list.Update()
$site_csom.load($list)
$site_csom.ExecuteQuery()
The Content-type xml defintion must contain this code related to the defaultViewID you want to use ( you need to check out which view ID you would like to use )
<XmlDocument NamespaceURI="http://schemas.microsoft.com/office/documentsets/welcomepageview">
<wpv:WelcomePageView xmlns:wpv="http://schemas.microsoft.com/office/documentsets/welcomepageview" ViewId="c7911cfe-c436-4b90-92a2-a88da10e6bed" />
</XmlDocument>
=> If you want a workaround for sharepoint online, please use this powershell docset welcomepage view setter and follow this example