Select to view content in your preferred language

How to make Export() is work with ArcGIS API for Silverlight!

2042
14
12-08-2011 06:19 PM
AnhTruong
Emerging Contributor
Hello ESRI expertise!

I like to export the data query from your ArcGIS API for Silverlight example to Excel.

You can see the data query at:
http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#QueryWithoutMap
to Excel file. In reality, I can export the data from silverlight datagrid using Export() function that you can refer to http://www.codeproject.com/KB/silverlight/SilverlightDataGridExport.aspx?msg=3297287

Please help to figure out how to export it in ArcGIS API for Silverlight??? Thanks.
0 Kudos
14 Replies
DominiqueBroux
Esri Frequent Contributor
0 Kudos
AnhTruong
Emerging Contributor
Thank for showing me the example to export ARCGIS query data with Map to Excel. In my case, I need to export ArcGIS query data without map from ArcGIS API for Silverlight that I learn from ArcGIS Resource Center. I am newbie, so I am not confident to make any change from your test code with Map query. Any further help are much appreciated. Thanks.


Darina gave a solution in these threads:
- http://forums.arcgis.com/threads/245...d-Excel-Export
- http://forums.arcgis.com/threads/13460-Export-to-Excel...
0 Kudos
AnhTruong
Emerging Contributor
Anyone know to export the QueryWithoutMap datagrid to excel file via Export button? I have read the Darina Tchountcheva FeatureDataGrid Excel Export with map, but I could not figure out how to modify without map in code. I am re-attached link http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#QueryWithoutMap for visualize what I need on data to export. I look forward any helps to solve my issue soon.
0 Kudos
DominiqueBroux
Esri Frequent Contributor
I tweaked the Darina's code to get it working with the sample you pointed out.

Attached are the sources and an example of output csv file.
0 Kudos
AnhTruong
Emerging Contributor
Hello Dominique,

I really appreciate your time and your ArcGIS expertise to help me out on this issue. Thanks again.

I tweaked the Darina's code to get it working with the sample you pointed out.

Attached are the sources and an example of output csv file.
0 Kudos
MaciejGolebiewski
Emerging Contributor
Hello,
I've got an error when implementing the code. 😞
It crashes when I click "Save" in "Save as... dialog", problem lies in this part:
private static string GetValue(FrameworkElement frameworkElement)
        {
            return frameworkElement is TextBlock ? (frameworkElement as TextBlock).Text : frameworkElement.ToString();
        }


The error says: "NullReferenceException was unhandled by user code"
I tried to workaround it this way:
private static string GetValue(FrameworkElement frameworkElement)
        {
            if (frameworkElement != null)
            {
                return frameworkElement is TextBlock ? (frameworkElement as TextBlock).Text : frameworkElement.ToString();
            }
        }

But then it underlines "GetValue" and says: "'ESRIMinimalMapApplication3.DataGridExtensions.GetValue(System.Windows.FrameworkElement)': not all code paths return a value"

Please help
0 Kudos
DominiqueBroux
Esri Frequent Contributor

But then it underlines "GetValue" and says: "'ESRIMinimalMapApplication3.DataGridExtensions.GetValue(System.Windows.FrameworkElement)': not all code paths return a value"

Please help

Not sure why this method gets called with a null value but to compile it, you need to return a value in case of null value.
Something like:
private static string GetValue(FrameworkElement frameworkElement)
        {
            if (frameworkElement != null)
            {
                return frameworkElement is TextBlock ? (frameworkElement as TextBlock).Text : frameworkElement.ToString();
            }
            else return null;
        }
0 Kudos
MaciejGolebiewski
Emerging Contributor
Thanks Dominique - that was fast reply!
It works but not completely correct... 😞
It exports only those rows which are currently visible on the screen (5 of them), depending on where I scroll the datagrid, I want it to export all values, even though they are below the scrollbar.
Another problem is that it exports empty XML.
Any solution?
EDIT:
Same situation concerning the values far to the right of the datagrid 😞
0 Kudos
DominiqueBroux
Esri Frequent Contributor
There are discussions about enhancements of this program in these threads:
  - http://forums.arcgis.com/threads/67767-Export-To-Excel-Downloaded-only-records-in-dialog-view
  - http://forums.arcgis.com/threads/63895-Export-To-Excel-Null-Reference-Error

Unfortunately, I am not sure someone published a new version grouping all the fixes.
0 Kudos