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

[BUG] New-PnPSitetemplateFromFolder removes first character of filenames #2944

Closed
1 of 6 tasks
martinlingstuyl opened this issue Mar 28, 2023 · 2 comments · Fixed by #2945
Closed
1 of 6 tasks

[BUG] New-PnPSitetemplateFromFolder removes first character of filenames #2944

martinlingstuyl opened this issue Mar 28, 2023 · 2 comments · Fixed by #2945
Assignees
Labels
bug Something isn't working

Comments

@martinlingstuyl
Copy link
Contributor

Reporting an Issue or Missing Feature

When running New-PnPSitetemplateFromFolder, a template is generated with files.

New-PnPSitetemplateFromFolder -Out "$PWD\site-template.xml" -Folder "$PWD\Files" -TargetFolder "some-target-folder" -Force

Results in:

<?xml version="1.0" encoding="utf-8"?>
<pnp:Provisioning xmlns:pnp="http://schemas.dev.office.com/PnP/2022/09/ProvisioningSchema">
  <pnp:Preferences Generator="PnP.Framework, Version=1.11.141.0, Culture=neutral, PublicKeyToken=0d501f89f11b748c" />
  <pnp:Templates ID="CONTAINER-FOLDEREXPORT">
    <pnp:ProvisioningTemplate ID="FOLDEREXPORT" Version="0" Scope="Undefined">
      <pnp:Files>
        <pnp:File Src="ome-file.pdf" Folder="some-target-folder" Overwrite="true" Level="Draft" />
        <pnp:File Src="some-file-2.pdf" Folder="some-target-folder" Overwrite="true" Level="Draft" />
      </pnp:Files>
    </pnp:ProvisioningTemplate>
  </pnp:Templates>
</pnp:Provisioning>

The first character of the filenames are removed (ome-file.pdf instead of some-file.pdf) when building the template.

The cause of this is the following line in ..\powershell\src\Commands\Provisioning\Site\NewSiteTemplateFromFolder.cs :

var unrootedPath = file.FullName.Substring(Folder.Length + 1);

The +1 is not needed here because .Substring() is zero-indexed while Folder.Length is not. The additional slash before the filename is therefore already ignored.

Expected behavior

I'd expect the full filenames

Actual behavior

The first character of the filenames are removed (ome-file.pdf instead of some-file.pdf) when building the template.

Steps to reproduce behavior

Run the script on a folder

What is the version of the Cmdlet module you are running?

1.11, 2.x nightly

Which operating system/environment are you running PnP PowerShell on?

  • Windows
  • Linux
  • MacOS
  • Azure Cloud Shell
  • Azure Functions
  • Other : please specify
@martinlingstuyl martinlingstuyl added the bug Something isn't working label Mar 28, 2023
@martinlingstuyl
Copy link
Contributor Author

You can assign me to fix this...

@veronicageek
Copy link
Collaborator

Thanks for contributing @martinlingstuyl 🙂

KoenZomers added a commit that referenced this issue Mar 30, 2023
…romFolder

Fixes issue with filenames in template output of New-PnPSitetemplateFromFolder. Closes #2944
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants