Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add to schema Functionality to set Document set view #190

Closed
KbWorks opened this issue Apr 6, 2017 · 15 comments
Closed

add to schema Functionality to set Document set view #190

KbWorks opened this issue Apr 6, 2017 · 15 comments

Comments

@KbWorks
Copy link

KbWorks commented Apr 6, 2017

It would be nice to have the possibility to add a view to a document set per listinstance.

pnp:Documentset
<pnp:contenttype id="" name="">
<pnp:view name="all documents"></pnp:view>
pnp:contenttype
</pnp:Documentset>

@PaoloPia
Copy link
Contributor

Hi,
Thanks for your feedback. The idea is great, and someone else already submitted it, too. However, we need to figure out how to implement this capability at the engine level.

@KbWorks
Copy link
Author

KbWorks commented May 21, 2017

Hi Paolo,

thank you i wrote a extension method for it maybe you can use it in the core in combination with the schema change.

@PaoloPia
Copy link
Contributor

PaoloPia commented Dec 5, 2017

Hi Paul,
Sorry for the delayed answer, where is the extension method? Is it in Core or in your own code somewhere else? Can you share it? Thanks.

@KbWorks
Copy link
Author

KbWorks commented Dec 5, 2017

Hi Paolo,

will look it up and send a message thanks again.

Paul

@KbWorks
Copy link
Author

KbWorks commented Dec 13, 2017

Hi Paulo,

have not tested if it still works but i can test it if you want.
` ///


/// sets the view for a Documentset welcome page.
///

/// The context.
/// The web.
/// The list.
/// The contenttype.
/// The contenttype.
private void SetDocumentSetView(ClientContext context, Web web, List spList, string pContentType, string welcomePageview)
{

        //var contenttype = spList.ContentTypes.GetById(pContentType);
        context.Load(spList, l => l.ContentTypes);
        context.ExecuteQuery();

        var contenttype = spList.ContentTypes.FirstOrDefault(c => c.Name == pContentType);
        var viewid = spList.GetViewByName(welcomePageview).Id;

        var docSetTemplate = DocumentSetTemplate.GetDocumentSetTemplate(context, contenttype);

        //context.Load(contenttype, c => c.SchemaXmlWithResourceTokens);
        context.Load(contenttype, c => c.SchemaXml, c => c.SchemaXmlWithResourceTokens);
        context.Load(docSetTemplate);
        context.ExecuteQuery();

        var xmlschema = string.IsNullOrEmpty(contenttype.SchemaXmlWithResourceTokens) ? contenttype.SchemaXml : contenttype.SchemaXmlWithResourceTokens;
        if (xmlschema.Contains("XmlDocuments"))
        {
            XmlDocument xmldocument = new XmlDocument();
            xmldocument.LoadXml(xmlschema);

            XmlNodeList xmldocs = xmldocument.SelectNodes("ContentType/XmlDocuments/XmlDocument");
            foreach (XmlNode xmldoc in xmldocs)
            {
                if (xmldoc.ChildNodes.Count > 0)
                {                    
                    var firstChildNodeName = xmldoc.FirstChild.Name;    //xmldoc.ChildNodes[0].Name;
                    if (firstChildNodeName == "WelcomePageView")
                    {
                        // Create new default view XML
                        string newDefaultViewXml = string.Format(@"<wpv:WelcomePageView xmlns:wpv='http://schemas.microsoft.com/office/documentsets/welcomepageview' ViewId='{0}' />", viewid);

                        // Replace default view XML
                        xmldoc.FirstChild.InnerXml = newDefaultViewXml;

                        // Exit foreach loop
                        break;
                    }
                }
            }

            StringWriter sw = new StringWriter();
            XmlTextWriter tx = new XmlTextWriter(sw);
            xmldocument.WriteTo(tx);
            xmlschema = sw.ToString();

             contenttype.Update(false);
           
        }
    }`

@PaoloPia
Copy link
Contributor

PaoloPia commented Apr 9, 2018

Hi @KbWorks,
We just added to the upcoming new schema version a XmlDocuments element for the DocumentSet. In the future, we will add corresponding functionality at the engine level. Thanks.

@PaoloPia PaoloPia closed this as completed Apr 9, 2018
@rajajii
Copy link

rajajii commented Jun 1, 2018

Hi KbWorks
Most likly your code is for SharePoint onpremises. I tried your approach on sharepoint online, but it did not work since SchemaXml is readonly property in online version.

Thanks anyway

@frankok
Copy link

frankok commented Jan 24, 2019

Hi @PaoloPia,
Is this now added and supported in 2018/07 schema, or has it just been added for future use?

@holylander
Copy link

holylander commented Oct 7, 2019

Hi @PaoloPia ,

I am trying to define the default view for a docset using this code
<pnp:XmlDocuments> <pnp:XmlDocument NamespaceURI="http://schemas.microsoft.com/office/documentsets/welcomepageview"> <pnp:WelcomePageView xmlns="http://schemas.microsoft.com/office/documentsets/welcomepageview" ViewId="539D3C0D-D299-494F-AC5D-DF603B0FFDB1" /> </pnp:XmlDocument> </pnp:XmlDocuments>
but It doesnt work. Any suggestion idea how to fulfill this? thanks!!

@holylander
Copy link

holylander commented Jan 21, 2020

Hi KbWorks
Most likly your code is for SharePoint onpremises. I tried your approach on sharepoint online, but it did not work since SchemaXml is readonly property in online version.

Thanks anyway

I can confirm the previous statement.
It seems there is not any way to implement this on sharepoint online so far
https://sharepoint.stackexchange.com/questions/256463/pnp-provisioning-welcomepageview-in-document-sets

On the other hand, if you are on premises you can change the documentset welcomepageview

@poidah
Copy link

poidah commented Jun 7, 2022

So here we are 5 years later and there doesn't seem to be a programatic or declaritive way to set the view to be used within a document set.

One would assume this would have to be a setting at the library level - this is because:

  • There are no views defined at a site level (along with site columns and site content types)
  • The library and the view need to exist for there to be a ViewID to reference

Please Microsoft, how do we use your tools in a scalable way?

@T-LeGranc
Copy link

So here we are 2 more years later and this is still not possible.

@MrRCG5
Copy link

MrRCG5 commented Aug 14, 2024

Can we update the "ViewId" in the "SchemaXML"? I tried and the SchemaXML is read-only.

@zenlord
Copy link

zenlord commented Aug 31, 2024

@MrRCG5 Yes, that's the way to do it currently, and it is pretty easy:

$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)`" />"

@MrRCG5
Copy link

MrRCG5 commented Sep 13, 2024

newDefaultViewXml

It is not working for me using SharePoint online. How is "$node.InnerXml" being updated? Do I need to execute or invoke a change?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants