SOLVED

Apply-PnPProvisioningTemplate : File not Found

Copper Contributor

Hello,
I have a problem using Apply-PnPProvisioningTemplate with PowerShell on a SharePoint Online context.

#website created to be used as a template
Connect-PnPOnline -Url "https://$principalWebSite/" –Credentials $adminCredentials
New-PnPWeb -Title "srcTemplate" -Url srctemplate -Description "srcTemplate"  -BreakInheritance -InheritNavigation -Template "STS#0" -Locale 1036
Disconnect-PnPOnline

#website exported as a template.pnp
Connect-PnPOnline –Url "https://$principalWebSite/srcTemplate" –Credentials $adminCredentials
Get-PnPProvisioningTemplate -Out $path/$file.pnp  -PersistBrandingFiles -PersistPublishingFiles
Disconnect-PnPOnline

#website created to be modified by the template
Connect-PnPOnline -Url "https://$principalWebSite/" –Credentials $adminCredentials
New-PnPWeb -Title "newWebSite" -Url newwebsite -Description "newWebSite"  -BreakInheritance -InheritNavigation -Template "STS#0" -Locale 1036
Disconnect-PnPOnline


#website modified by the template
Connect-PnPOnline -Url "https://$principalWebSite/newwebsite" –Credentials $adminCredentials
Set-PnPTraceLog -On -LogFile $path/$file.xml -Level Debug
Apply-PnPProvisioningTemplate -Path $modelePath #-Handlers Pages -ExcludeHandlers Lists
Set-PnPTraceLog -Off
Disconnect-PnPOnline

Error Message : File not found
Apply-PnPProvisioningTemplate : Fichier introuvable.
Au caractère Ligne:3 : 1
+ Apply-PnPProvisioningTemplate -Path $modelePath #-Handlers Pages -Exc ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (:) [Apply-PnPProvisioningTemplate], ServerException
    + FullyQualifiedErrorId : EXCEPTION,SharePointPnP.PowerShell.Commands.Provisioning.ApplyProvisioningTemplate

srcTemplate File is founded and I can see that it is working for a while (attachments, lists, library, etc.) and this it stop with this error.

 

srcTemplate & log file in attachment.

Does anyone have an idea ?

18 Replies

A common solution to that error is to open the template file look for the File references and ensure that all those files are available on the relative location where your template is located.

 

For example, if you have a <pnp:File> element referencing a file on "/MyFilesExample/MyFile.txt", next to the template file you will need a "MyFilesExample" folder and inside that folder a "MyFile.txt".

 

This happens in some scenarios, but it's generally easy to fix as you can just create the required folders and download the required files from the original site that was used as a template.

 

Note: I have assumed that you are doing this in 2 steps

- create site and save template

("fix" template)

- create site and apply template

 

Hope this helps

 

 

Hi, Yes I have already read about this.
To be sure that it is not this problem, I have made my test on an empty website.
How you can see, my command Get-PnPProvisioningTemplate -Out arrive just after the creation of the website. I haven't added/deleted/changed nothing before...

I have read that it was possible to rename the .pnp to .zip, and to look if there is a "pnp:file" in the <guid>.xml file of the folder named "Files".
But there is nothing....

That's correct, you can extract the contents of the file as if it was a zip.
Check also for other references other than pnp:file elements. For example, a custom site icon can also cause this if I'm not wrong.
It will be worth quickly checking your entire template.
Also, check if the master pages are not referenced (generally close to the bottom of the template)
And forgot about theme files as well.
And also, very likely, the link to the OneNote file on the navigation element. Quite sure this is a common issue as well. There is a way to generate that link dynamically
I have also seen this error lately, and it doesn't seem to happen every time. All of the files in the <pnp:Files> node are in the same directory. The template gets partially applied to the site (e.g. Lists/Libs are there), but fails with File Not Found before uploading the Files. Sometimes if I immediately re-run the Apply-PnPProvisioningTemplate command it works without error. Bizarre.

@Jeremy GOUPIL just checked your template and I think it's the OneNote reference on navigation.

<pnp:NavigationNode Title="Bloc-notes" Url="{site}/_layouts/15/WopiFrame.aspx?sourcedoc={137c43e8-57b9-4f2f-a6ba-0d50fa98c1c5}&amp;action=editnew" IsExternal="true" />

 

Try removing this line and try again as it should work

I'm experiencing the same issue: tried about everything but don't know why I always get this error:

 

PowerShell_ISE.exe Information: 0 : 2018-09-16 22:45:56.6430 [Provisioning] [14] [Debug] Code execution scope ended 107192ms 656c838b-f844-4709-b8fb-2372ae42169f
Apply-PnPProvisioningTemplate : File Not Found.
At line:3 char:1
+ Apply-PnPProvisioningTemplate -Path "C:\temp\PatrimoniumTeamSiteTempl ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (:) [Apply-PnPProvisioningTemplate], ServerException
+ FullyQualifiedErrorId : EXCEPTION,SharePointPnP.PowerShell.Commands.Provisioning.ApplyProvisioningTemplate

 

I don't think I'm referencing to any document in the provisioning xml.

xml file in the attachments

Maybe a link to the OneNote file on the left navigation? I've seen this as the cause of the problem multiple times

Hello @Jeremy GOUPIL - Looking at your Powershell code, are you setting a value for the $modelePath variable used for the Apply-PnPProvisioningTemplate?

I've also tried using the -ExcludeHandler Navigation parameter, I get the same error
best response confirmed by Jeremy GOUPIL (Copper Contributor)
Solution
I've found the lines causing the Error:

After each List Instance, there is a Field "_DisplayName" that gets updated: the .xml looks like this:
<pnp:Fields>
<Field ID="{1a53ab5a-11f9-4b92-a377-8cfaaf6ba7be}" Name="_DisplayName" DisplaceOnUpgrade="TRUE" Sortable="FALSE" Filterable="FALSE" Hidden="FALSE" ReadOnly="TRUE" ShowInFileDlg="FALSE" Type="Lookup" DisplayName="Sensitivity" List="Docs" ListInternal="IpLabelCache" FieldRef="LabelId" ShowField="DisplayName" LeftList="Docs" LeftColumnName="IpLabelId" JoinColName="LabelId" JoinRowOrdinal="0" JoinType="LEFT OUTER" SchemaVersion="16.0.162.0" RecreateIfMissing="TRUE" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="_DisplayName" FromBaseType="TRUE" />
</pnp:Fields>

I removed this Field Updates and was able to apply my template as I wanted. This bug seems to have been reported already (And fixes but not merged yet): https://github.com/SharePoint/PnP-Sites-Core/pull/1911

We ran into this issue with our c# provisioning system today as well and, as mentioned, solved by removing this field from the template:

var pnpTemplate = web.GetProvisioningTemplate(ptci);

foreach (var list in pnpTemplate.Lists)
{
    list.Fields.RemoveAll(d => d.SchemaXml.Contains("_DisplayName"));
};

 

Hello,
I have already deleted the OneNote file from my website before creating the template. I have even deleted the file from the site's bin. And the link in the navigation bar has been deleted too. This is not my problem :\

Hi, yes, it is the same $path than the one used to export the template at the beginning.
I can see that SharePoint is reading and uploading things in lists but at one moment, it crashes.

Hi Jeremy,

There is a bug in the provisioning schema causing this error. try to find the field Name="_DisplayName" within your template.xml (there are multiple of them) are remove those fieds ;)

Check out my post a bit up in the thread for more Infos

So I have renamed srcTemplate.pnp to srcTemplate.zip
Extracted srcTemplate.zip
Edited this file : \Files\<guid>.xml

I have deleted :
<Field ID="{1a53ab5a-11f9-4b92-a377-8cfaaf6ba7be}" Name="_DisplayName" DisplaceOnUpgrade="TRUE" Sortable="FALSE" Filterable="FALSE" Hidden="FALSE" ReadOnly="TRUE" ShowInFileDlg="FALSE" Type="Lookup" DisplayName="{res:Field_Niveau_de_confidentialité_DisplayName}" List="Docs" ListInternal="IpLabelCache" FieldRef="LabelId" ShowField="DisplayName" LeftList="Docs" LeftColumnName="IpLabelId" JoinColName="LabelId" JoinRowOrdinal="0" JoinType="LEFT OUTER" SchemaVersion="16.0.162.0" RecreateIfMissing="TRUE" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="_DisplayName" FromBaseType="TRUE" />


and

 

<Field ID="{1a53ab5a-11f9-4b92-a377-8cfaaf6ba7be}" Name="_DisplayName" DisplaceOnUpgrade="TRUE" Sortable="FALSE" Filterable="FALSE" Hidden="FALSE" ReadOnly="TRUE" ShowInFileDlg="FALSE" Type="Lookup" DisplayName="{res:Field_Niveau_de_confidentialité_DisplayName}" List="Docs" ListInternal="IpLabelCache" FieldRef="LabelId" ShowField="DisplayName" LeftList="Docs" LeftColumnName="IpLabelId" JoinColName="LabelId" JoinRowOrdinal="0" JoinType="LEFT OUTER" SchemaVersion="16.0.162.0" RecreateIfMissing="TRUE" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="_DisplayName" FromBaseType="TRUE" />


and

 

<Field ID="{1a53ab5a-11f9-4b92-a377-8cfaaf6ba7be}" Name="_DisplayName" DisplaceOnUpgrade="TRUE" Sortable="FALSE" Filterable="FALSE" Hidden="FALSE" ReadOnly="TRUE" ShowInFileDlg="FALSE" Type="Lookup" DisplayName="{res:Field_Niveau_de_confidentialité_DisplayName}" List="Docs" ListInternal="IpLabelCache" FieldRef="LabelId" ShowField="DisplayName" LeftList="Docs" LeftColumnName="IpLabelId" JoinColName="LabelId" JoinRowOrdinal="0" JoinType="LEFT OUTER" SchemaVersion="16.0.162.0" RecreateIfMissing="TRUE" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="_DisplayName" FromBaseType="TRUE" />

Zipped to srcTemplate.zip
Renamed to srcTemplate.pnp

 

Apply-PnPProvisioningTemplate : The Provisioning Template URI srcTemplate.xml is not valid.

Hi Jeremy,

Try to save your template to e.g. srcTemplate.xml and edit it in Visual Studio Code, or any other editor of your choice.
Don't forget to delete the lines just above, and below the field you removed before. Those are <pnp:Fields> and </pnp:Fields>

If i take one of your fields as example, you shoulde remove the following:

<pnp:Fields>
<Field ID="{1a53ab5a-11f9-4b92-a377-8cfaaf6ba7be}" Name="_DisplayName" DisplaceOnUpgrade="TRUE" Sortable="FALSE" Filterable="FALSE" Hidden="FALSE" ReadOnly="TRUE" ShowInFileDlg="FALSE" Type="Lookup" DisplayName="{res:Field_Niveau_de_confidentialité_DisplayName}" List="Docs" ListInternal="IpLabelCache" FieldRef="LabelId" ShowField="DisplayName" LeftList="Docs" LeftColumnName="IpLabelId" JoinColName="LabelId" JoinRowOrdinal="0" JoinType="LEFT OUTER" SchemaVersion="16.0.162.0" RecreateIfMissing="TRUE" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="_DisplayName" FromBaseType="TRUE" />
</pnp:Fields>

Then save your xml file and use that to apply your template ;). You can also attach your xml file so that i can have a quick look at it for other inconsistencies

Okay sorry my mistake !

Its finally works... almost haha :)

 

I have created Home page with new experience but it is not keeped. Page file has been removed. But it is another problem. I gonna Google it.

 

Thanks a lot everybody !

 

1 best response

Accepted Solutions
best response confirmed by Jeremy GOUPIL (Copper Contributor)
Solution
I've found the lines causing the Error:

After each List Instance, there is a Field "_DisplayName" that gets updated: the .xml looks like this:
<pnp:Fields>
<Field ID="{1a53ab5a-11f9-4b92-a377-8cfaaf6ba7be}" Name="_DisplayName" DisplaceOnUpgrade="TRUE" Sortable="FALSE" Filterable="FALSE" Hidden="FALSE" ReadOnly="TRUE" ShowInFileDlg="FALSE" Type="Lookup" DisplayName="Sensitivity" List="Docs" ListInternal="IpLabelCache" FieldRef="LabelId" ShowField="DisplayName" LeftList="Docs" LeftColumnName="IpLabelId" JoinColName="LabelId" JoinRowOrdinal="0" JoinType="LEFT OUTER" SchemaVersion="16.0.162.0" RecreateIfMissing="TRUE" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="_DisplayName" FromBaseType="TRUE" />
</pnp:Fields>

I removed this Field Updates and was able to apply my template as I wanted. This bug seems to have been reported already (And fixes but not merged yet): https://github.com/SharePoint/PnP-Sites-Core/pull/1911

View solution in original post