Copied to clipboard

Flag this post as spam?

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


  • Ajay Karwal 31 posts 149 karma points
    Jul 31, 2015 @ 16:27
    Ajay Karwal
    0

    CSV Import of a list of retail stores

    Hi, this may have been posted in the wrong category - its my first post here.

    I'm in the process of creating a Store Finder facility which reads a list of stores within Umbraco and plots them on a map.

    All is working fine. However, I'm having to manually add each store. As the list of stores is approaching 600+, this is going to put me into an early grave!

    Is there a simple way of importing a CSV list of all stores and have the columns match up to the corresponding properties in my DocType?

    My structure is as follows:

    StoresList (Doctype: 'StoresList')
        Store 1 (DocType: 'StoreDetails')
            Name
            Address
            Postcode
            Latitude
            Longitude
        Store 2
            ...
    

    So for each row in the CSV I want to create a new Store under StoresList

    I have SQL access.

    Any help would be greatly appreciated.

  • Anders Bjerner 487 posts 2990 karma points MVP 8x admin c-trib
    Jul 31, 2015 @ 20:47
    Anders Bjerner
    0

    Hi Ajay and welcome to Our,

    Do you have an example of the CSV file?

    Anyways, rather than writing to the database directly, you can use Umbraco's content service. I'm assuming you only have do to this import once, so you can simply use one of your views - this could look like:

    @using Umbraco.Core.Services
    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{
        Layout = "Master.cshtml";
    }
    
    @{
    
        // ID of the arent (eg. the ID of your "StoreList")
        int idOfParent = 1234;
    
        // Get a reference to the content service
        IContentService cs = UmbracoContext.Current.Application.Services.ContentService;
    
        // Create a new content item ("Store 1" will be the name)
        IContent store = cs.CreateContent("Store 1", idOfParent, "StoreDetails");
    
        // Update any properties
        store.SetValue("address", "Somehwere");
    
        // Save and publish the content item (store)
        cs.SaveAndPublishWithStatus(store);
    
    }
    

    This example only adds a single store, but it gives an idea on how to add content. By using the content service, everything is added correctly, an the content item (store) will also automatically be published.

  • Richard Soeteman 4046 posts 12899 karma points MVP 2x
    Aug 03, 2015 @ 07:13
    Richard Soeteman
    0

    Hi,

    Have you found CMSImport? Really easy to import csv into Umbraco. If you use two files you can even use the free version

    http://soetemansoftware.nl/cmsimport

    Hope you can use this.

    Best,

    Richard

Please Sign in or register to post replies

Write your reply to:

Draft