1

There are many PDF files in our project that are manually added to the media library.

I see that some of them have the template - /sitecore/templates/System/Media/Versioned/Pdf and some others - /sitecore/templates/System/Media/Unversioned/Pdf

  1. Why does this happen. I'm sure the author would not select any settings to have it uploaded as 'Versioned'.And this happend with image files too.

  2. I would like to change all versioned pdf to unversioned pdf.

When I try this power shell script, it throws an error:

$master = [Sitecore.Configuration.Factory]::GetDatabase("master");
$entryTemplate = $master.Templates["/sitecore/templates/System/Media/Unversioned/Pdf"];
cd master:"\media library\Files\Test";
Get-ChildItem -recurse | ForEach-Object { if ($_.TemplateName -eq "Pdf") { $_.ChangeTemplate($entryTemplate) } };

Exception calling "ChangeTemplate" with "1" argument(s): "Value cannot be null. Parameter name: template" At line:8 char:76 + ... ($.TemplateName -eq "Pdf") { $.ChangeTemplate($entryTemplate) } }; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : ArgumentNullException

Exception calling "ChangeTemplate" with "1" argument(s): "Value cannot be null. Parameter name: template" At line:8 char:76 + ... ($.TemplateName -eq "Pdf") { $.ChangeTemplate($entryTemplate) } }; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : ArgumentNullException

Using Sitecore 8.2 update 3

  • have you tried adding " characters around "master:\media library\files\Test"? – Marek Musielak Mar 16 '18 at 7:00
  • @MarekMusielak I just tried and it threw a new exception. Updated in question. Please have a look. – Qwerty Mar 16 '18 at 7:07
  • 1
    Try $entryTemplate = $master.Templates["System/Media/Unversioned/Pdf"]; – Marek Musielak Mar 16 '18 at 7:11
  • @MarekMusielak That worked!!! Thank you so much. Could you please post it so that i can mark it as an answer. I would also appreciate if you could mention the reason for that path and also why this issue occurs. Thanks again. – Qwerty Mar 16 '18 at 7:20
  • Comments converted into an answer – Marek Musielak Mar 16 '18 at 7:25
2

First, wrap your media library test files path with " characters.

Then instead of passing the whole path to $master.Templates:

$master.Templates["/sitecore/templates/System/Media/Unversioned/Pdf"];

use only template specific subpath

$master.Templates["System/Media/Unversioned/Pdf"];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.