Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7982301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:38:29+00:00 2026-06-04T10:38:29+00:00

I’ve done some research into this but not sure I understand all the pieces

  • 0

I’ve done some research into this but not sure I understand all the pieces that need to go into the following problem.

My client needs a special template to be used instead of the auto detected media templates in the Media Library if they upload to a certain Folder. The template has special fields. The template can also house different types of files (PDFs, vendor specific formats, executables).

For development purposes we are currently uploading the file and then doing a template switch afterwards but what really needs to happen is that file be uploaded to that template type in the first place. I was wondering if there was a way to hook into the upload process to make sure the special template is used when underneath a certain path in the Media Library? If so, where should I start?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T10:38:31+00:00Added an answer on June 4, 2026 at 10:38 am

    We recently had to do something similar. Along the same line as techphoria414, I’d tap into the upload save pipeline. Then, to make it a bit more generic and reusable, use the power of Sitecore’s configuration parsing to hook everything up to your handler. Here’s what we ended up with.

    Main class with required “Process” method:

    public class ChangeTemplate
    {
        public string Name { get; set; }
        public string Path { get; set; }
        public List<ChangedMediaTemplate> Templates { get; set; }
    
        public ChangeTemplate()
        {
            Templates = new List<ChangedMediaTemplate>();
        }
    
        public void Process(UploadArgs args)
        {
            var db = Sitecore.Context.ContentDatabase;
    
            var uploadPath = db.GetItem(args.Folder).Paths.ContentPath;
            if (!uploadPath.StartsWith(Path))
            {
                // Not uploading to designated folder
                return;
            }
    
            foreach (var item in args.UploadedItems)
            {
                // Need to change template for this item?
                var changedTemplate = Templates.Where(t => t.Old.Equals(item.Template.FullName)).FirstOrDefault();
                if (changedTemplate != null)
                {
                    var newTemplate = db.Templates[changedTemplate.New];
                    try
                    {
                        item.ChangeTemplate(newTemplate);
                    }
                    catch (Exception e)
                    {
                        Log.Error("Unable to change {0} template on upload of {1} to {2}.".FormatWith(Name, item.Name, uploadPath), e, this);
                    }
                }
            }
        }
    }
    

    Minor supporting class:

    public class ChangedMediaTemplate
    {
        public string Old { get; set; }
        public string New { get; set; }
    }
    

    And then the config:

    <processors>
        <uiUpload>
          <processor patch:after="*[@type='Sitecore.Pipelines.Upload.Save, Sitecore.Kernel']" mode="on" type="Foo.Project.SitecoreX.Pipelines.Upload.ChangeTemplate, Foo.Project.Classes">
            <Name>Product Images</Name>
            <Path>/sitecore/media library/Images/Foo/products</Path>
            <Templates hint="list">
              <Template type="Foo.Project.SitecoreX.Pipelines.Upload.ChangedMediaTemplate, Foo.Project.Classes">
                <Old>System/Media/Unversioned/Image</Old>
                <New>User Defined/Foo/Product/Image/Unversioned/Product Image</New>
              </Template>
              <Template type="Foo.Project.SitecoreX.Pipelines.Upload.ChangedMediaTemplate, Foo.Project.Classes">
                <Old>System/Media/Unversioned/Jpeg</Old>
                <New>User Defined/Foo/Product/Image/Unversioned/Product Jpeg</New>
              </Template>
              <Template type="Foo.Project.SitecoreX.Pipelines.Upload.ChangedMediaTemplate, Foo.Project.Classes">
                <Old>System/Media/Versioned/Image</Old>
                <New>User Defined/Foo/Product/Image/Versioned/Product Image</New>
              </Template>
              <Template type="Foo.Project.SitecoreX.Pipelines.Upload.ChangedMediaTemplate, Foo.Project.Classes">
                <Old>System/Media/Versioned/Jpeg</Old>
                <New>User Defined/Foo/Product/Image/Versioned/Product Jpeg</New>
              </Template>
            </Templates>
          </processor>
        </uiUpload>
    </processors>
    

    Modifying or adding new template rules becomes as simple as editing the config as needed.

    Hope this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I'm not entirely sure how I managed to jack this up. http://pretty-senshi.com If you
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
This could be a duplicate question, but I have no idea what search terms
I know there's a lot of other questions out there that deal with this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.