Select to view content in your preferred language

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

2046
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
MaciejGolebiewski
Emerging Contributor
Glad we have you here Dominique!
I encountered another problem when implementing your code (print screen attached).
From where it gets the wrong path? Everything beside this seems to be OK.
I have "graphic.Attributes["NAMN"]" in further code, but it should only add values to query combobox:
private void QueryTask_ExecuteCompleted(object sender, ESRI.ArcGIS.Client.Tasks.QueryEventArgs args)
        {
            FeatureSet featureSet = args.FeatureSet;

            // If initial query to populate states combo box
            if ((args.UserState as string) == "initial")
            {
                // Just show on initial load
                QueryComboBox.Items.Add("Select...");
                
                foreach (Graphic graphic in args.FeatureSet.Features)
                {
                    QueryComboBox.Items.Add(graphic.Attributes["NAMN"].ToString());
                }


                QueryComboBox.SelectedIndex = 0;
                return;
            }

I also changed variable "graphic" to "graphic2" in ExportToExcel part of code, but it still gets wrong Path, just like it's looking in the wrong service.
I have no clue what I'm doing wrong... 😞
0 Kudos
DominiqueBroux
Esri Frequent Contributor
It seems Darina gave a fix second post of this thread.
Hopefully it's the same issue as yours.
0 Kudos
MaciejGolebiewski
Emerging Contributor
Yes, I'm already using the code corrected by you actually (2nd zip).
Tomorrow I will try the last hope - Darina's suggestion to add "IEnumerable<Graphic> graphics"
If that doesn't work I have no idea how to fix it, I still got no clue why it's getting wrong binding path... 😕
0 Kudos
DominiqueBroux
Esri Frequent Contributor
From your screenshot, it seems you are not using the latest version which adds lots of checking.

It should be:

private static string GetValue(DataGridColumn col, Graphic graphic)
        {
            if (col is DataGridBoundColumn)
            {
                DataGridBoundColumn column = col as DataGridBoundColumn;
                if ((column.Binding != null) && (column.Binding.Path != null))
                {
                    string path = column.Binding.Path.Path;
                    if (!string.IsNullOrEmpty(path))
                    {
                        var att = Regex.Replace(path, ".*\\[(.*)\\]", "$1");
                        return graphic.Attributes[path] == null ? string.Empty : graphic.Attributes[path].ToString();
                    }                    
                }                
            }
            return string.Empty;
        }
0 Kudos
MaciejGolebiewski
Emerging Contributor
Oh my...
The problem was I specified wrong Binding Path for a column in XAML, it couldn't find the attribute value, because such attribute field doesn't exist in specified service, that's the reason for my NullReference error...
So dumb mistake... :mad:
Sorry for bothering you and many thanks for your effort! 🙂

The problem with XML files is still up-to-date, but they aren't empty as i thought before - maybe it's a problem with my Excel?
Could you please check for me if the XML opens correctly into your Excel? (file attached)
0 Kudos