Thank you for reporting an issue or suggesting an enhancement. We appreciate your feedback - to help the team to understand your needs, please complete the below template to ensure we have the necessary details to assist you. If you have a actual question, we would ask you to use [SharePoint
[X ] Bug
[ ] Enhancement
[X ] Office 365 / SharePoint Online
[ ] SharePoint 2016
[ ] SharePoint 2013
Custom document templates on content types should be supported by PnP. This measn that generated templates using get-PnPProvisioningTemplate should also export the Word document template file.
When my templates include custom document templates for content types
<pnp:ContenType>
...
</pnp:FieldRefs>
<pnp:DocumentTemplate TargetName="Letter template.docx" />
</pnp:ContentType>
Then I'm getting the following errors:
2017-01-27T11:40:56.1594563Z powershell.exe Information: 0 : 2017-01-27 11:40:56.1594 [Content Types] [5] [Debug] Updating existing Content Type: 0x01010051BED5400B132D4582CAA9998CC4F84501 - CPO Letter 6407ms 3c788103-5107-4b54-b6df-84685c3e76a8
2017-01-27T11:40:56.1824580Z powershell.exe Information: 0 : 2017-01-27 11:40:56.1824 [Content Types] [5] [Debug] Updating property DocumentTemplate 6430ms 3c788103-5107-4b54-b6df-84685c3e76a8
2017-01-27T11:40:56.3503407Z powershell.exe Information: 0 : 2017-01-27 11:40:56.3493 [Content Types] [5] [Debug] Code execution scope ended 6597ms 3c788103-5107-4b54-b6df-84685c3e76a8
2017-01-27T11:40:56.3503407Z powershell.exe Information: 0 : 2017-01-27 11:40:56.3493 [Provisioning] [5] [Debug] Code execution scope ended 115954ms 3c788103-5107-4b54-b6df-84685c3e76a8
2017-01-27T11:40:56.5703418Z ##[error]urlOfFile
Parameter name: Specified value is not supported for the urlOfFile parameter.
2017-01-27T11:40:56.7282519Z ##[error]You cannot call a method on a null-valued expression.
This results in the PnP Temlate apply to fail.
Create content type with custom template (make sure that the file name is not the standard one)
You could fix this by first uploading the document template file using templateA.xml and then creating the content type using templateB.xml. We use this approach in our test automation: see https://github.com/SharePoint/PnP-Sites-Core/blob/dev/Core/OfficeDevPnP.Core.Tests/Framework/Functional/Templates/contenttype_files.xml and https://github.com/SharePoint/PnP-Sites-Core/blob/dev/Core/OfficeDevPnP.Core.Tests/Framework/Functional/Templates/contenttype_add.xml.
I agree that this would be nice enhancement for the engine, but it's not simply grabbing the file and downloading it, it also means requires a more dynamic way of executing handlers. Will flag this one as enhancement.
I also stumbled upon this error today doing a simple "web.GetProvisioningTemplate" and "web.ApplyProvisioningTemplate" with a content type having a custom template.
The problem is that the exported template cannot be directly used to apply to a new web, what would be my expected behaviour. If you are not exporting content (which is fine) it would be nice to not reference the custom template within a content type at all, since it will always break the code and throws a not-so-easy-to-explain exception _urlOfFile_.
I currently work around the issue by removing the DocumentTemplate from the template before applying the template to a web, e.g.:
foreach( var cType in template.ContentTypes)
{
cType.DocumentTemplate = null;
}
We managed to reproduce the error, so marking as bug.
internal testing feedback:
Followed the steps as mentioned by user.
Got below error when provisioned.
Apply-PnPProvisioningTemplate : urlOfFile
Parameter name: Specified value is not supported for the urlOfFile parameter.
Is there plans to fix this?
@jansenbe any progress on this issue since March '17?
Also, could you elaborate on the work-around you mentioned above? I have 4-5 Content Types (published from the CT Hub) which have custom document templates associated and am seeing the same error @Pieter-Veenstra reported.
I have the same issue. I have 5 content types with custom document template
I don't have any custom template for any custom content type and I have the same issue. Any walk around? Any fix? Any plan for future?
@jansenbe Is there any update on this?
We are also facing the same issue. is there any solution or plan to fix this issue in upcoming releases?
I am wondering if this would be ever resolved. Even if the template is exported, there's currently no way to apply a pnp template and include the library template. I just faced this issue with form libraries. I have the xsn files, I can upload the file to the "Forms" folder too, but something is missing, it just not gets "published" the same way InfoPath does.
I'm also seeing the same behaviour. I created the PnP file for my site, which includes the default Documents library. When I apply this template to a new site, I get the Invalid template URL, The template must exist in the Forms directory of this document library.
If I remove the document template setting from the list template:
DocumentTemplate="{site}/Shared Documents/Forms/Customer Documents/template.dotx"
the Apply-PnpProvisioningTemplate process finishes. Using the Feb 2019 r2 release in PowerShell.
Same behaviour with CSOM.
Wow, stumbled over this one today. +1
Hi, made myself a fix into our provisioning module. There is 2 things happening here :
1 - Get provisioning will not get files from templates, so I built myself one that upload locally the files like the rest of provisioning.
2 - Apply provisioning expect a relative path that reach the file into the local folder within "TargetName". The first step does not push the right path by default (there is no file anyway).
So, to fix these two conditions :
1 - get locally the files from the template inmemory
2 - Fix the path "TargetName"
3 - Save the provisioning
So here are my methods, sorry its in french :
private void ObtenirDefaultDocuments(Web web,Model.ContentType cntType,ProvisioningTemplate template,PnPMonitoredScope scope)
{
// Trouver le fichier template de documents si celui-ci est pr茅sent dans le template.
if (cntType.DocumentTemplate != null)
{
var cntTypeSite = web.GetContentTypeById(cntType.Id);
cntTypeSite.EnsureProperty(t => t.DocumentTemplateUrl);
var fullUri = new Uri(UrlUtility.Combine(web.Url, cntTypeSite.DocumentTemplateUrl.Replace(web.ServerRelativeUrl, "")));
var folderPath = fullUri.Segments.Take(fullUri.Segments.Count() - 1).ToArray().Aggregate((i, x) => i + x).TrimEnd('/');
var fileName = fullUri.Segments[fullUri.Segments.Count() - 1];
var file = web.GetFileByServerRelativeUrl(cntTypeSite.DocumentTemplateUrl);
file.EnsureProperties(f => f.Level, f => f.ServerRelativeUrl);
var containerPath = folderPath.StartsWith(web.ServerRelativeUrl) && web.ServerRelativeUrl != "/"
? folderPath.Substring(web.ServerRelativeUrl.Length)
: folderPath;
var container = containerPath.Trim('/').Replace("%20", " ");
var src = !string.IsNullOrEmpty(container) ? $"/{container}/{fileName.Replace("%20", " ")}" : fileName.Replace("%20", " ");
cntType.DocumentTemplate = src;
var homeFile = new Model.File()
{
Folder = Tokenize(folderPath, web.Url),
Src ="." + src,
Overwrite = true,
Level = (Model.FileLevel)Enum.Parse(typeof(Model.FileLevel), file.Level.ToString()),
};
TelechargerFichierTemplate(web, file, container, homeFile, scope);
scope.LogDebug($"Default document {fileName} added for contentType {cntType.Name}");
}
}
private void TelechargerFichierTemplate(Web web,File file, string container,Model.File homeFile,PnPMonitoredScope scope)
{
using (var stream = File.OpenBinaryDirect((ClientContext)file.Context, file.ServerRelativeUrl).Stream)
{
var path = System.IO.Path.Combine(Provision._repertoire, container);
try
{
System.IO.Directory.CreateDirectory(path);
path = System.IO.Path.Combine(Provision._repertoire, homeFile.Src);
using (var fileStream = System.IO.File.Create(path))
{
stream.CopyTo(fileStream);
};
}
catch (Exception ex)
{
scope.LogError(ex, $"Erreur lors de la sauvegarde du fichier {path}");
throw;
}
}
}
@Micael-stack , this looks promising, but I am afraid I don't know how to use it.
My goal is to provision each new sharepoint online site created by the user with a set of custom branded templates reachable from the new button in the document library.
I have created the content types with their associated templates and exported them via Get-PnPProvisioningTemplate. Then I have created a flow (power Automate) that executes every time a new site is created. It runs Apply-PnPProvisioningTemplate. But it fails as the content types documenttemplate attribute value isn't valid - it has only the name of the template.
The Azure function in Power Automate looks like this:
$in = Get-Content $triggerInput -Raw
Write-Output "Incoming request for '$in'"
Connect-PnPOnline -AppId $env:SPO_AppId -AppSecret $env:SPO_AppSecret -Url $in
Write-Output "Connected to site"
Any help is highly appreciated,
Peeter
Hi, with the model provided by https://github.com/SharePoint/PnP-Sites-Core/blob/dev/Core/OfficeDevPnP.Core.Tests/Framework/Functional/Templates/contenttype_files.xml i can create a document with a specific model but the content type field is positionned on "Document" instead of "Specific Content Type".
How to fix it ?
I ran across this one today as well. Any updates as to when (if ever) this will be fixed as we're now going on 4 years of this being an open bug?
Most helpful comment
@jansenbe any progress on this issue since March '17?
Also, could you elaborate on the work-around you mentioned above? I have 4-5 Content Types (published from the CT Hub) which have custom document templates associated and am seeing the same error @Pieter-Veenstra reported.