PnP - defaultdocuments

Copper Contributor

I try to provision document set with default documents using PnP Provisioning template for SharePoint Online.

 

I make document set from UI, and set default documents on the web's content type. Then I GetProvisioningTemplate and save it as xml file. In the content of that file I see sections for defautl documents, it looks like this:

<pnp:ContentTypes>
        <pnp:ContentType ID="0x0120D52000DA2BDE301472174F98F7F5E4DAD162FD" Name="Shared document set" Description="" Group="SIG content types" NewFormUrl="_layouts/15/NewDocSet.aspx" EditFormUrl="" DisplayFormUrl="">
          <pnp:FieldRefs>
            <pnp:FieldRef ID="c042a256-787d-4a6f-8a8a-cf6ab767f12d" Name="ContentType" />
            <pnp:FieldRef ID="b824e17e-a1b3-426e-aecf-f0184d900485" Name="ItemChildCount" />
            <pnp:FieldRef ID="960ff01f-2b6d-4f1b-9c3f-e19ad8927341" Name="FolderChildCount" />
            <pnp:FieldRef ID="fa564e0f-0c70-4ab9-b863-0177e6ddd247" Name="Title" Hidden="true" />
            <pnp:FieldRef ID="8553196d-ec8d-4564-9861-3dbe931050c8" Name="FileLeafRef" Required="true" />
            <pnp:FieldRef ID="cbb92da4-fd46-4c7d-af6c-3128c2a5576e" Name="Description" />
          </pnp:FieldRefs>
          <pnp:DocumentSetTemplate>
            <pnp:AllowedContentTypes>
              <pnp:AllowedContentType ContentTypeID="0x0101" />
            </pnp:AllowedContentTypes>
            <pnp:DefaultDocuments>
              <pnp:DefaultDocument Name="Enquiry Docs.txt" ContentTypeID="0x0101" FileSourcePath="" />
              <pnp:DefaultDocument Name="Construction Issue Costing.txt" ContentTypeID="0x0101" FileSourcePath="" />
            </pnp:DefaultDocuments>
          </pnp:DocumentSetTemplate>
        </pnp:ContentType>
      </pnp:ContentTypes>

Then I try to ApplyProvisioningTemplate to some other website. I got exception

Value cannot be null. Parameter name: stream
   at Microsoft.SharePoint.Client.FileFolderExtensions.UploadFile(Folder folder, String fileName, Stream stream, Boolean overwriteIfExists)
   at OfficeDevPnP.Core.Framework.Provisioning.ObjectHandlers.ObjectFiles.UploadFile(ProvisioningTemplate template, File file, Folder folder, Stream stream)
   at OfficeDevPnP.Core.Framework.Provisioning.ObjectHandlers.ObjectFiles.ProvisionObjects(Web web, ProvisioningTemplate template, TokenParser parser, ProvisioningTemplateApplyingInformation applyingInformation)
   at OfficeDevPnP.Core.Framework.Provisioning.ObjectHandlers.SiteToTemplateConversion.ApplyRemoteTemplate(Web web, ProvisioningTemplate template, ProvisioningTemplateApplyingInformation provisioningInfo)
   at Microsoft.SharePoint.Client.WebExtensions.ApplyProvisioningTemplate(Web web, ProvisioningTemplate template, ProvisioningTemplateApplyingInformation applyingInformation)
   at pnpdemo.Program.ApplyProvisioningTemplate(String webUrl, String userName, SecureString passwordSecure, String provisioningTemplateName) in c:\Users\lkorpowski\Documents\Visual Studio 2013\Projects\pnpdemo\pnpdemo\Program.cs:line 62
   at pnpdemo.Program.Main(String[] args) in c:\Users\lkorpowski\Documents\Visual Studio 2013\Projects\pnpdemo\pnpdemo\Program.cs:line 33
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

I guess the problem is that in the provisioning template there are no content of default docuemnts. There is only the name of the files, but no content.

Is it possible to store defaultdocuments as well as the content of those file in the provisioning template xml? Or does anyone solve this issue somehow?

I tried to follow the sample

https://github.com/SharePoint/PnP-Provisioning-Schema/blob/master/Samples/ProvisioningSchema-2016-05...

but it also does not have any content of the defaultdocuments

 

2 Replies

Try adding a connector to your template object pointing to for instance the file system using a file system connector type. The template tries to find the named document in your template, but it cannot find it now, because no connector is attachted.

 

template.Connector = new FileSystemConnector(resourcesFolderConnectionString, fileConnectorContainer);

 

where template is your ProvisioningTemplate object, resourcesFolderConnectionString is this case should be the path to your file on your file system and fileConnecorContainer should be the folder to look in.

Thank you Robert for reply.

I had set template.Connector to the FileSystemConnector.

 

I managed to not get the exception by setting the value of FileSourcePath

<pnp:DefaultDocument Name="test.txt" ContentTypeID="0x0101" FileSourcePath="test.txt" />

But it still does not work - now I just don't get the exception, but the defaultDocuments in SharePoint is not set.

 

 

I prepared Enquiry Docs.txt (with some lorem ipsum content) and put in in the same folder where I have provisioning template xml file.

The template.Connector points to that location.

I tried different combinations of FileSystemConnector paramanters, but without success.

I also tried different FileSourcePath e.g. "./SharedDocumentSet/test.txt" with spaces, without, with %20 etc. None works for me.

 

 

Lets say that I have both provisioningtemplate.xml and test.txt file in c:\

my code looks like this

using (var context = new ClientContext(webUrl))
            {
                context.Credentials = new SharePointOnlineCredentials(userName, passwordSecure);
                Web web = context.Web;
                context.Load(web, w => w.Title);
                context.ExecuteQueryRetry();

                Console.WriteLine(context.Web.Title);

                XMLTemplateProvider provider = new XMLFileSystemTemplateProvider(
                    @"C:\",
                    "");
                ProvisioningTemplate template = provider.GetTemplate("provisioningTemplate.xml");

                ProvisioningTemplateApplyingInformation ptai = new ProvisioningTemplateApplyingInformation();
                ptai.ProgressDelegate = delegate(string message, int progress, int total)
                {
                    Console.WriteLine("{0:00}/{1:00} - {2}", progress, total, message);
                };
                template.Connector = new FileSystemConnector(
                    @"C:\",
                    "");
                web.ApplyProvisioningTemplate(template, ptai);
            }

and the provisioning template file has following content

<?xml version="1.0"?>
<pnp:Provisioning xmlns:pnp="http://schemas.dev.office.com/PnP/2016/05/ProvisioningSchema">
  <pnp:Preferences Generator="OfficeDevPnP.Core, Version=2.6.1608.0, Culture=neutral, PublicKeyToken=3751622786b357c2" />
  <pnp:Templates ID="CONTAINER-TEMPLATE-844EC56385FF4D2592104866A575CD15">
    <pnp:ProvisioningTemplate ID="TEMPLATE-844EC56385FF4D2592104866A575CD15" Version="1" BaseSiteTemplate="BLANKINTERNET#0">
      <pnp:ContentTypes>
        <pnp:ContentType ID="0x0120D52000DA2BDE301472174F98F7F5E4DAD162FD" Name="SharedDocumentSet" Description="" Group="my custom content types" NewFormUrl="_layouts/15/NewDocSet.aspx" EditFormUrl="" DisplayFormUrl="">
          <pnp:FieldRefs>
            <pnp:FieldRef ID="c042a256-787d-4a6f-8a8a-cf6ab767f12d" Name="ContentType" />
            <pnp:FieldRef ID="b824e17e-a1b3-426e-aecf-f0184d900485" Name="ItemChildCount" />
            <pnp:FieldRef ID="960ff01f-2b6d-4f1b-9c3f-e19ad8927341" Name="FolderChildCount" />
            <pnp:FieldRef ID="fa564e0f-0c70-4ab9-b863-0177e6ddd247" Name="Title" Hidden="true" />
            <pnp:FieldRef ID="8553196d-ec8d-4564-9861-3dbe931050c8" Name="FileLeafRef" Required="true" />
            <pnp:FieldRef ID="cbb92da4-fd46-4c7d-af6c-3128c2a5576e" Name="Description" />
          </pnp:FieldRefs>
          <pnp:DocumentSetTemplate>
            <pnp:AllowedContentTypes>
              <pnp:AllowedContentType ContentTypeID="0x0101" />
            </pnp:AllowedContentTypes>
            <pnp:DefaultDocuments>
              <pnp:DefaultDocument Name="test.txt" ContentTypeID="0x0101" FileSourcePath="test.txt" />
            </pnp:DefaultDocuments>
          </pnp:DocumentSetTemplate>
        </pnp:ContentType>
      </pnp:ContentTypes>
    </pnp:ProvisioningTemplate>
  </pnp:Templates>
</pnp:Provisioning>

Could you please provide me a working sample? Or point the place which I have to correct?