23/07/2016 - 2 minute read
Import any CSV File into Umbraco with the Umbraco LINQPad Driver
I've recently successfully imported data from a large CSV file into Umbraco using Shannon Deminick's useful Umbraco LINQPad driver. Here's a high-level overview of how I did it: You can import any valid CSV file through this process, and infact, it would work with any data format parseable in .NET - LINQPad provides a full scriptable .NET environment.
Setting up LINQPad
You'll need to install the Umbraco LINQPad driver so that your local LINQPad can connect to your Umbraco installation. Note that you can only connect to a local Umbraco installation, not a copy running on a remote server. You'll have to deploy your data using an Umbraco package.
Now, you should be able to follow Shannon's documentation to get LINQPad setup (taken from the README.md in the GitHub repository)
- In LinqPad, Click "Add Connection"
- Click "View more drivers"
- Select "Browse"
- Add the
UmbracoLinqPad.lpxfile that you've downloaded
- Choose your Umbraco installation root folder
LinqPAD should then have a connection available for your local Umbraco installation, as shown in the screenshot above.
Writing the Import Script
You'll have to write a little custom .NET code in LINQPad to take your CSV file and create the content nodes in Umbraco using the Umbraco API (specifically the content service).
LINQPad provides a full scriptable .NET environment for you to play with. If you've ever done this kind of thing in .NET or worked with LINQPad before, you should be able to improvise.
Though I can't provide a one-size-fits-all solution here, here's a little example code to get you started. Playing with code and your particular CSV file's schema should yield some quick results for you.
Make sure the "language" is set to "C# Program" in the dropdown list at the top of the editor in LINQPad. This will enable you to write a full program instead of a single C# statement inside LINQPad.
Deploying from your local Umbraco to a live environment
Now, because LINQPad can't connect to a live Umbraco environment, you'll have to deploy the new content nodes you've created to your live environment manually. I did this with a package.
- Open your local Umbraco backoffice. Expand Developer > Packages
- Right-click on "Created Packages" and click "Create Package". Fill in the package meta-data like Name, Version, License, etc. (There are required fields)
- Select the content nodes you'd like to deploy in the right-hand pane.
- Make sure you include any document types the new content nodes depend on when you're creating the package.
- Click "save", and then click "publish"
- A download link will now be available in the "Package Properties" tab. Download the package and remember where you left it.
Installing the package on the server
This should be as easy as installing any other package.
- Go to the backoffice in your live environment and expand Developer > Packages
- Click on "Install Local Package" and follow the on-screen instructions
This process is very flexible and has allowed me to import a diverse range of information into Umbraco. There are some drawbacks, however:
Umbraco LINQPad driver has Certain Limitations
The Umbraco LINQPad driver is very handy, but certain parts of the Umbraco API depend on a WebContext and HTTP/Web Server environment which the LINQPad driver cannot provide.
The Umbraco Packaging Process is Slow and Unreliable with Large Amounts of Data
I think my package was on the brink of being too big, because the package install and content publish process took **aaages**. I did think it started hanging at one point and refreshed the screen, but the install and publish process relies on the browser session not being refreshed halfway through.
Thanks for reading! If you enjoyed this post and would like to get in touch, find me on twitter @glcheetham.
About the author
Gary Lewis Cheetham is an automotive marketing specialist, born and raised in Oldham, Greater Manchester. He spent his teenage years working at the family dealership after school, learning the ropes of the car trade from the inside out.
After moving on to working in marketing, Gary Lewis founded GL Digital in 2020 when he noticed a need for direct-to-consumer marketing platforms within the auto industry. He now strives every day to help independent dealers in the UK and US realise their potential. Gary also loves Formula 1 and motorsport.
We will be the first to say it: SEO for car dealerships is officially over in 2022. Car dealers fail at SEO time and time again, because…
5 minute read - 07/02/2022
This article will cover how dealerships can do conversion rate optimisation on their website and sales funnels, including for lead…
6 minute read - 27/01/2022
Email marketing is one of the most effective digital marketing strategies for car dealerships to build relationships with customers. It…
5 minute read - 27/01/2022