Edit feature attachments

View inAndroidFormsUWPWPFWinUIiOSView on GitHubSample viewer app

Add, delete, and download attachments for features from a service.

Image of edit feature attachments

Use case

Attachments provide a flexible way to manage additional information that is related to your features. Attachments allow you to add files to individual features, including: PDFs, text documents, or any other type of file. For example, if you have a feature representing a building, you could use attachments to add multiple photographs of the building taken from several angles, along with PDF files containing the building's deed and tax information.

How to use the sample

Tap a feature to load its attachments. Use the buttons to save, delete, or add attachments.

How it works

  1. Create a ServiceFeatureTable from a URL.
  2. Create a FeatureLayer object from the service feature table.
  3. Select features from the feature layer with FeatureLayer.SelectFeatures().
  4. To fetch the feature's attachments, cast to an ArcGISFeature and useArcGISFeature.GetAttachmentsAsync().
  5. To add an attachment to the selected ArcGISFeature, create an attachment and use ArcGISFeature.AddAttachmentAsync().
  6. To delete an attachment from the selected ArcGISFeature, use the ArcGISFeature.DeleteAttachmentAsync().
  7. After a change, apply the changes to the server using ServiceFeatureTable.ApplyEditsAsync().

Relevant API

  • ApplyEditsAsync
  • DeleteAttachmentAsync
  • FeatureLayer
  • FetchAttachmentsAsync
  • FetchDataAsync
  • ServiceFeatureTable
  • UpdateFeatureAsync

Additional information

Attachments can only be added to and accessed on service feature tables when their HasAttachments property is true.

Tags

data, image, JPEG, PDF, picture, PNG, TXT

Sample Code

EditFeatureAttachments.xamlEditFeatureAttachments.xamlEditFeatureAttachments.xaml.cs
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<UserControl x:Class="ArcGISRuntime.WPF.Samples.EditFeatureAttachments.EditFeatureAttachments"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:esri="http://schemas.esri.com/arcgis/runtime/2013">
    <Grid>
        <esri:MapView x:Name="MyMapView" />
        <Border Style="{StaticResource BorderStyle}">
            <Grid>
                <StackPanel Orientation="Vertical">
                    <Label HorizontalContentAlignment="Center"
                           Content="Tap features to select."
                           FontWeight="SemiBold" />
                    <ListBox x:Name="AttachmentsListBox"
                             MinHeight="100"
                             MaxHeight="300"
                             HorizontalContentAlignment="Stretch"
                             Background="LightGray"
                             IsEnabled="False">
                        <!--  ItemTemplate defines how each item (Attachment) is rendered.  -->
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="*" />
                                        <ColumnDefinition Width="Auto" />
                                        <ColumnDefinition Width="Auto" />
                                    </Grid.ColumnDefinitions>
                                    <Label Content="{Binding Name}" />
                                    <!--  DataTemplate sets the item as the button's DataContext automatically.  -->
                                    <Button Grid.Column="1"
                                            Margin="0,0,5,0"
                                            Padding="5"
                                            HorizontalAlignment="Right"
                                            Click="DownloadAttachment_Click"
                                            Content="Download" />
                                    <Button Grid.Column="2"
                                            Padding="5"
                                            HorizontalAlignment="Right"
                                            Click="DeleteAttachment_Click"
                                            Content="Delete" />
                                </Grid>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>
                    <Button x:Name="AddAttachmentButton"
                            Margin="0,5,0,5"
                            Click="AddAttachment_Click"
                            Content="Add attachment"
                            IsEnabled="False" />
                    <ProgressBar x:Name="ActivityIndicator"
                                 Height="15"
                                 IsIndeterminate="True"
                                 Visibility="Collapsed" />
                </StackPanel>
            </Grid>
        </Border>
    </Grid>
</UserControl>

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.