Data Import/Export
Getting data into and out of a Visual Studio LightSwitch application isn’t hard but does require some coding. At a very high level, we’ll add a button to a LightSwitch form and then add code behind the button to do the dirty work. In this example, I’ll use a grid for the basic on-screen display tool and then export/import data through the rows of the grid.
We’ll use a slight variation of our previous myTask app as the starting point but add the ability to read in a CSV file with new tasks. Make sure to change the summary property of the Tasks table to Title and the UserInformationList to Name. The key here is the use of the Excel extension referenced previously in this chapter. The good news here is that it will also import CSV files. We’re going to add more information by using the current user name to attach to the Task Created By field.
Here’s what the CSV file we’ll be importing looks like:
Title,Start Date,Due Date Initiate Proposal Process,12/30/2011,1/20/2012 First Draft Due,1/20/2012,2/3/2012 Form Proposal Team,12/30/2011,1/6/2012 Start Project,12/30/2011,3/2/2012 Team Kickoff Meeting, 1/6/2012, 1/6/2012 Team Status Meeting #1,1/13/2012,1/13/2012 Team Status Meeting #2,1/20/2012,1/20/2012
Notice the first line has field names and match the field names of the Tasks list. This will make it easy to pair the fields between the import file and the target Task list when we run the program.
To get started, we’ll use our standard approach with a connection to the demo ...
Get SharePoint Apps with LightSwitch now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.