View attachments as hyperlink in popups

3524
8
12-27-2011 09:30 AM
JamesFournier
New Contributor II
I consider myself a non-devloper/programmer so the Silverlight Viewer is a big help in getting applications up and running.  I'd like to know, does anyone have any suggestions on how I could go about getting feature attachments to display as a hyperlink in the popups.  I'd like to emulate the way this works in ArcMap and ArcGIS Online instead of having to use the view attachments button.
0 Kudos
8 Replies
MichelleThompson1
New Contributor II
I have a similar question except I want a link to show up in the identify results window using the Silverlight API. I figured out how to create a link for one attachment, but not for more than one attachment.

I added a hyperlink button to the bottom of the identify results window and, in the c# code, pulled the first data value (object ID) from the selected feature in the comboBox and added that to the hyperlink uri. The attachment ID seemed to match the feature object ID. However, I am not sure how the attachment ID for the second one is generated so I am not able to create a link to it. I'm trying to access the feature attachment infos property, but I am not sure how to do so.

Anyway, I hope that this gives you a little more info on how one might go about it. I'm not very familiar with the Viewer though.

The attachment editor would be great except we don't want users to be able to add or delete attachments. Plus having a link in the identify results window would be more user friendly in our case.

Thanks,
Michelle
0 Kudos
ChrisGraves1
New Contributor II
Hi,

I've set-up a hyperlink base in ArcMap and want to be able to view hyperlinks using a tool much the same as in ArcMap. Is there the option to add a hyperlink tool in Sliverlight 3.1? Because the full path is not in the attribute field, I can't access the hyperlink from the attribute table only from the hyperlink tool.

Thanks,
Chris
0 Kudos
BobNichols
New Contributor III
If you are displaying your results in a datagrid you can create a template column to properly format your hyperlink and build the first part of the url to your file.  For example if in your attribute table you are only storing the attachment file name, file.pdf for example, you could create a template column in your xaml like this:


<UserControl.Resources>
    <DataTemplate x:Key="DocSource">
        <HyperlinkButton Foreground="White" NavigateUri="{Binding Attributes[source_doc], StringFormat=http://www.YourSite/SourceDocs/\{0\}}" Content="{Binding Attributes[source_doc]}" TargetName="_blank" />
     </DataTemplate>
</UserControl.Resources>


Then in your QueryTask_ExecuteCompleted you would build the datagrid columns at runtime, rather than before hand.  As you loop through the featureset to generate your columns you listen for the field source_doc.  When you get to that column you generate the column using the DataTemplate above.

ExecuteCompleted Code


if (featureSet != null && featureSet.Features.Count > 0)
            {
    int rec = 0;
                foreach (var feature in featureSet.Features)
                    feature.Attributes["Rec"] = ++rec;
   
   
                List<string> fields = new List<string>();
               
                //generate the first column for record index
                DataGridTextColumn dataGridTextColumnRec = new DataGridTextColumn();
                Binding Recbinder = new Binding();
                Recbinder.Path = new PropertyPath("Attributes[Rec]");
                dataGridTextColumnRec.Header = "Rec";
                Recbinder.Mode = BindingMode.OneWay;
                dataGridTextColumnRec.Binding = Recbinder;
                QueryDetailsDataGrid.Columns.Add(dataGridTextColumnRec);

                //generate the other columns
                foreach (var item in featureSet.FieldAliases)
                {
                    if (item.Value == "source_doc") //Create a hyperlink column for document link
     {
      DataGridTemplateColumn templateColumn = new DataGridTemplateColumn();
      templateColumn.Header = "Source Doc";
      templateColumn.CellTemplate = (DataTemplate)Resources["DocSource"];
      QueryDetailsDataGrid.Columns.Add(templateColumn);
     }
     else
     {
     DataGridTextColumn dataGridTextColumn = new DataGridTextColumn();
                    Binding binder = new Binding();
                    fields.Add(item.Value);   //FieldAliases is a Dictionary, the field name being the key and the field alias being the value.
                    binder.Path = new PropertyPath("Attributes[" + item.Key + "]");
                    dataGridTextColumn.Header = item.Value;
                    binder.Mode = BindingMode.TwoWay ;
                    dataGridTextColumn.Binding = binder;
                    QueryDetailsDataGrid.Columns.Add(dataGridTextColumn);
     }
                }
   
    foreach (Graphic feature in featureSet.Features)
                {
                 feature.Symbol = LayoutRoot.Resources["DefaultResultLineSymbol"] as LineSymbol;
                 selectionGraphicslayer.Graphics.Insert(0, feature);
                }
   
    
   
   }


You can create as many data templates as you need, then add another if statement to listen for them.

Hope this helps!
0 Kudos
JennB
by
New Contributor III
I have a similar question except I want a link to show up in the identify results window using the Silverlight API. I figured out how to create a link for one attachment, but not for more than one attachment.

I added a hyperlink button to the bottom of the identify results window and, in the c# code, pulled the first data value (object ID) from the selected feature in the comboBox and added that to the hyperlink uri. The attachment ID seemed to match the feature object ID. However, I am not sure how the attachment ID for the second one is generated so I am not able to create a link to it. I'm trying to access the feature attachment infos property, but I am not sure how to do so.

Anyway, I hope that this gives you a little more info on how one might go about it. I'm not very familiar with the Viewer though.

The attachment editor would be great except we don't want users to be able to add or delete attachments. Plus having a link in the identify results window would be more user friendly in our case.

Thanks,
Michelle


Michelle,

Did you ever find a solution to this? I'm looking to do something similar and have tried a few things with no luck.
0 Kudos
AhmedEl-Sisi
Occasional Contributor III
Michelle,

Did you ever find a solution to this? I'm looking to do something similar and have tried a few things with no luck.

Use FeatureLayer::QueryAttachmentInfos to get list of attachments then bind it to ItemsControl contains hyperlink or whatever you want.

  featureLayer.QueryAttachmentInfos(selectedGraphic, (Action<IEnumerable<ESRI.ArcGIS.Client.FeatureService.AttachmentInfo>>)QueryAttachmentInfosCallback,
                              (Action<Exception>)delegate(Exception ex) { MessageBox.Show(ex.ToString());});

  private void QueryAttachmentInfosCallback(IEnumerable<ESRI.ArcGIS.Client.FeatureService.AttachmentInfo> attachments)
   {
            //Bind to Itemscontrol
   }
0 Kudos
JennB
by
New Contributor III
Use FeatureLayer::QueryAttachmentInfos to get list of attachments then bind it to ItemsControl contains hyperlink or whatever you want.

  featureLayer.QueryAttachmentInfos(selectedGraphic, (Action<IEnumerable<ESRI.ArcGIS.Client.FeatureService.AttachmentInfo>>)QueryAttachmentInfosCallback,
                              (Action<Exception>)delegate(Exception ex) { MessageBox.Show(ex.ToString());});

  private void QueryAttachmentInfosCallback(IEnumerable<ESRI.ArcGIS.Client.FeatureService.AttachmentInfo> attachments)
   {
            //Bind to Itemscontrol
   }


I suppose the problem I'm having is that the Identify widget/tool doesn't work on Feature Layers (they have to be just a dynamic service layer). So, I can't use FeatureService stuff if I want the layers to be identifiable. 😕
0 Kudos
brettangel
Occasional Contributor II
A simple no code necessary method we implemented uses a virtual directory and http link in the feature.
0 Kudos
AhmedEl-Sisi
Occasional Contributor III
I suppose the problem I'm having is that the Identify widget/tool doesn't work on Feature Layers (they have to be just a dynamic service layer). So, I can't use FeatureService stuff if I want the layers to be identifiable. 😕


You can Just Query the REST
Attachment info for a feature (featureId 1) in a dynamic layer (existing map service layer with id 3):
http://myServer/arcgis/rest/services/Census/MapServer/dynamicLayer/1/attachments?layer={"id":101,"source":{"type":"mapLayer","mapLayerId":3}}&where=1=1&f=pjson


For more information check the following link:
http://resources.arcgis.com/en/help/rest/apiref/ms_dyn_attachmentinfos.html
0 Kudos