Copied to clipboard

Flag this post as spam?

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


  • suzyb 476 posts 934 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 4054 posts 12927 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 476 posts 934 karma points
    May 26, 2016 @ 09:47
    suzyb
    0

    Thanks for the response Richard.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies