Select to view content in your preferred language

Exporting Selected Records from Feature Layer to .CSV File?

7442
14
12-20-2013 06:52 AM
IanPeebles
Frequent Contributor
I am interested in adding in functionality that allows the user to select records from a feature layer and then have them export them to a .csv file.  I checked the JS API and samples and did not see this functionality.  I do not want a shapefile or feature class exported, just a table.  Users who will be using this will not have an ArcGIS Desktop install.

Has anyone been able to get something like this to work?  Would be very interested in your ideas.  Thanks.
0 Kudos
14 Replies
JeffJacobson
Frequent Contributor
Instead of trying to use a GeoProcessing service, I would write a server-side component in your web site. The handler would take the user selected data as input, serialize the JSON to classes, and then write the CSV equivalent.

What kind of server are you running? If you are running ASP.NET I would recommend using the following libraries for this.

  • ServiceStack: This is for easily creating a REST endpoint. There is also a library for JSON serialization.

  • CsvHelper This library is for converting your classes into CSV. [Edit: I think ServiceStack on its own suports CSV output, so you probably don't need CSVHelper after all.]

0 Kudos
TimCollyer
Regular Contributor
I more or less use jacobsj's approach (I have a tomcat/java server).

I did investigate ways of doing this using the File API, but I gave up because IE8 doesn't support it if I recall correctly. I'm not sure if it is possible or not though.
0 Kudos
ReneRubalcava
Esri Frequent Contributor
How about coverting the features to JSON and convert the JSON to csv directly on the client?
http://stackoverflow.com/questions/4130849/convert-json-format-to-csv-format-for-ms-excel
0 Kudos
JeffJacobson
Frequent Contributor
I more or less use jacobsj's approach (I have a tomcat/java server).

I did investigate ways of doing this using the File API, but I gave up because IE8 doesn't support it if I recall correctly. I'm not sure if it is possible or not though.


You are correct, IE8 doesn't support File API. I think you would also need FileWriter, which most browsers don't support.
0 Kudos
TimCollyer
Regular Contributor
How about coverting the features to JSON and convert the JSON to csv directly on the client?
http://stackoverflow.com/questions/4130849/convert-json-format-to-csv-format-for-ms-excel


Yeah, this looks nice.
0 Kudos