Copied to clipboard

Flag this post as spam?

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


  • Matt Bliss 176 posts 234 karma points c-trib
    Feb 01, 2012 @ 13:45
    Matt Bliss
    0

    Import based on Url?

    I have an Umbraco site populated with data and want to set up the content of the 301 redirects field (uComponents: umbraco301MovedPermanently) with urls for an old site. This field is in a base doctype that all other doctypes inherit from.

    Is it possible to run an import based on having a column in my data source with the address of the page I want to import values into rather than a start location and doctype?

  • Richard Soeteman 4046 posts 12899 karma points MVP 2x
    Feb 01, 2012 @ 15:11
    Richard Soeteman
    0

    Hi Matthew,

    If I understand correctly. You have an already existing site? CMSImport will only insert records, or update records that are previous imported with CMSImport It is possible to have a dynamic location if you add 3 lines of code in the importing event. But changing doctypes is not possible since Umbraco doesn't allow a document type of a document to be changed. Maybe you can import per doctype?

    Cheers,

    Richard

  • Matt Bliss 176 posts 234 karma points c-trib
    Feb 01, 2012 @ 15:56
    Matt Bliss
    0

    Thanks Richard,

    I don't need the import to change the doc type of a record, I just need the import to work for whatever doctype it finds at the specified path.

    The 'dynamic location' sounds like it might be what I need. What are the three lines of code?

    Many thanks,

    Matt

     

  • Richard Soeteman 4046 posts 12899 karma points MVP 2x
    Feb 02, 2012 @ 08:09
    Richard Soeteman
    0

    Hi Matt,

    Sorry for the late reply. Documents are created with the assigned doctype, after that it is not possible to change that, so it will not changed the doctype at the specific path.

    Dynamic location can be achieved with the following class, change e.Items["location"] to the field you use in your datasource.

        public class MoveDocumentEvent : ApplicationBase
        {
            public MoveDocumentEvent()
            {
                ContentImport.RecordImported += new ContentImport.RecordImportedEventHandler(ContentImport_RecordImported);
            }
    
            /// <summary>
            /// Moves the library to the correct section.
            /// </summary>
            /// <param name="sender">The source of the event.</param>
            /// <param name="e">The <see cref="CMSImport.Extensions.Import.RecordImportedEventArgs"/> instance containing the event data.</param>
            void ContentImport_RecordImported(object sender, RecordImportedEventArgs e)
            {
                if (e.ImportAction != ImportActions.Skip && e.Items.ContainsKey("location"))
                {
                    Document doc = sender as Document;
                    if (doc != null)
                    {
                        doc.Move((int)e.Items["location"]);
                    }
                }
            }
        }

    Hope this helps,

    Richard

  • Matt Bliss 176 posts 234 karma points c-trib
    Feb 02, 2012 @ 12:10
    Matt Bliss
    0

    Hi Richard,

    Thanks for that, If I've undestood that correctly it would allow for restructuring a site based on an import file which is a very powerful feature, but is beyond what I need. Sorry if I've not explained the requirement clearly. I think it should be straight forward.

    What I need is quite simple...

    • I don't want to move any documents
    • I don't want to change any doctypes
    • I want to find the a record based on a column in the CSV file that holds it's relative Url whatever doctype it might be
    • Having found the record I would like to import a value from another column into a field.

    The reason for my question is that the interface requires

    1. A start node (Which I guess could be the root) and 
    2. A doctype (but I don't want to be limited to just one)

    Sorry if I've not explained it clearly

    Thanks, Matt

  • Richard Soeteman 4046 posts 12899 karma points MVP 2x
    Feb 03, 2012 @ 09:25
    Richard Soeteman
    0

    Ah ok,

    So you can still add a static mapping based on the dropdownlist and when a record in your database matches that datatype you will import it, otherwise you skip it?

    Sorry if I ask stupid questions.

  • Matt Bliss 176 posts 234 karma points c-trib
    Feb 03, 2012 @ 12:14
    Matt Bliss
    0

    Thanks Richard, 

    I appreciate your help. I'll have a look at that later and see how that works.

    Matt

  • Richard Soeteman 4046 posts 12899 karma points MVP 2x
    Mar 07, 2012 @ 09:48
    Richard Soeteman
    0

    Hi Matthew,

    Just a check up did it work for you?

    Thanks,

    Richard

  • Matt Bliss 176 posts 234 karma points c-trib
    Mar 07, 2012 @ 14:03
    Matt Bliss
    0

    Hi Richard,

    I didn't get it to work with in the time I had available so I stopped trying and made a change of direction and set the 301 redirects up using Url rewriting instead of trying to import them into the umbraco301MovedPermanently field. 

    I think it might have worked okay if the original content had been imported using CMS import, but actually the content had just been entered using the normal web interface and I didn't have time to persue it further.

    Many thanks for your help though!

    Matt

Please Sign in or register to post replies

Write your reply to:

Draft