0

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?

3 Answers 3

1

I've tried the code provided by Alberto S. for an on premises environment (SharePoint SE, which is very similar to SharePoint 2019). I'm running into the error message on update that SchemaXML is readonly and cannot be updated. This occurs when I update the content type through the list object as well as directly on the content type object. It also occurs with PowerShell as well in C#. The content type is not read only.

It seems not to be possible to update the schema XML of the content type.

1

(At least today) this is quite easy, albeit that indeed no dedicated function exists. But one can set the default welcome page view combining PnP and XML:

$welcomePageView = Get-PnPView -Identity $view.Displayname -List $list
$xml = [xml](Get-PnPContentType -Identity $ctType.Name -List $library | Select -Expand SchemaXml)
$node = $xml.ContentType.XmlDocuments.XmlDocument | where {$_.NamespaceURI -eq 'http://schemas.microsoft.com/office/documentsets/welcomepageview'}
$node.InnerXml = "<wpv:WelcomePageView xmlns:wpv=`"http://schemas.microsoft.com/office/documentsets/welcomepageview`" ViewId=`"$($welcomePageView.Id)`" />"

//EDIT: this is not working - I must have tested the wrong variables when I wrote this answer. The SchemaXml property of the (list) content type is read-only and cannot be updated

0

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>

More info on github over here

=> If you want a workaround for sharepoint online, please use this powershell docset welcomepage view setter and follow this example

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.