Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • suzyb 474 posts 932 karma points
    May 24, 2016 @ 09:21
    suzyb
    0

    Import into Archetype

    Does anyone have any experience in importing values into archetype using CMSImport.

    I need to import 3 values in separate columns of an excel file into an archetype, making each value a separate item. Has anyone ever imported into archetype that could guide me in the right direction, not sure where to start.

  • Richard Soeteman 4046 posts 12899 karma points MVP 2x
    May 24, 2016 @ 09:36
    Richard Soeteman
    100

    Hi Suzy,

    Since Archetype is too flexible (almost a document type of itself) this is only possible with the recordsimporting/recordimported event. This gives you a list of all the properties that you can set. Then you need to convert that to something ArcheType accepts and you can store it on the document property.

    Below a sample. To get this to work you need a reference to Umbraco.Core, CMSImport.Extensions and CMSImport.Library dll's

    using CMSImportLibrary.Providers.ImportProviders.Content;
    using Umbraco.Core;
    using Umbraco.Core.Models;
    
    namespace EventSample
    {
    public class EventTester :ApplicationEventHandler
    {
        protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            ContentImportProvider.RecordImporting += ContentImportProvider_RecordImporting;
        }
    
        void ContentImportProvider_RecordImporting(object sender, CMSImport.Extensions.Providers.ImportProviders.EventArgs.RecordImportingEventArgs e)
        {
            var doc = sender as IContent;
            var prop1 = e.Items["key1"];
            var prop2 = e.Items["key2"];
            var prop3 = e.Items["key3"];
    
            //Do something with ArcheType
            doc.SetValue("ArcheType", your archetypevalue here);
    
        }
    }
    

    }

    I hope this helps you,

    Richard

  • suzyb 474 posts 932 karma points
    May 26, 2016 @ 09:47
    suzyb
    0

    Thanks for the response Richard.

Please Sign in or register to post replies

Write your reply to:

Draft