Forum Discussion
PnP - defaultdocuments
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.
- Leszek KorpowskiMay 11, 2017Copper Contributor
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?