This sample demonstrates using the ESRI.ArcGIS.Client.Toolkit AttachmentEditor to upload, download, and delete files associated with selected features in an ArcGISLocalFeatureLayer.
To use the sample, select a point feature and click the 'Add' button to attach a file. To download an attachment for a selected feature, click the hyperlink for the filename. To delete an attachment associated with a selected feature click the red X next to the file name
<UserControlx:Class="ArcGISWPFSDK.LocalToolkitAttachmentEditor"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/client/2009"><Gridx:Name="LayoutRoot"Background="White"><Grid.Resources><BooleanToVisibilityConverterx:Key="BooleanToVisibilityConverter"/><LinearGradientBrushx:Key="PanelGradient"EndPoint="0.5,1"StartPoint="0.5,0"><LinearGradientBrush.RelativeTransform><TransformGroup><ScaleTransformCenterY="0.5"CenterX="0.5"/><SkewTransformCenterY="0.5"CenterX="0.5"/><RotateTransformAngle="176"CenterY="0.5"CenterX="0.5"/><TranslateTransform/></TransformGroup></LinearGradientBrush.RelativeTransform><GradientStopColor="#FF145787"/><GradientStopColor="#FF3D7FAC"Offset="0.184"/><GradientStopColor="#FF88C5EF"Offset="0.984"/></LinearGradientBrush><esri:SimpleRendererx:Key="MySimplePointRenderer"><esri:SimpleRenderer.Symbol><esri:SimpleMarkerSymbolColor="Orange"/></esri:SimpleRenderer.Symbol></esri:SimpleRenderer></Grid.Resources><esri:Mapx:Name="MyMap"Loaded="MyMap_Loaded"WrapAround="True"Extent="-15000000,2000000,-7000000,8000000"Background="#FFE3E3E3"MinimumResolution="2445.98490512499"><esri:ArcGISLocalTiledLayerID="BaseMap"Path="..\\Data\\TPKs\\Topographic.tpk"/><esri:ArcGISLocalFeatureLayerID="PointsofInterest"Path="..\\Data\\MPKS\\PointsofInterest.mpk"LayerName="PointsofInterest"AutoSave="False"Editable="True"Initialized="LocalFeatureLayer_Initialized"OutFields="*"></esri:ArcGISLocalFeatureLayer></esri:Map><GridHorizontalAlignment="Right"VerticalAlignment="Top"Margin="0,15,15,0"><RectangleFill="{StaticResource PanelGradient}"Stroke="Gray"RadiusX="10"RadiusY="10"Margin="0,0,0,5"><Rectangle.Effect><DropShadowEffect/></Rectangle.Effect></Rectangle><RectangleFill="#FFFFFFFF"Stroke="DarkGray"RadiusX="5"RadiusY="5"Margin="10,10,10,15"/><StackPanelx:Name="myStack"Orientation="Vertical"><TextBlockText="Click on a point feature to select it, and click the 'Add' button to attach a file."Width="275"TextAlignment="Left"Margin="20,20,20,5"TextWrapping="Wrap"FontWeight="Bold"Foreground="Black"/><esri:AttachmentEditorx:Name="attachmentEditor"VerticalAlignment="Top"Margin="20,5,20,20"Background="WhiteSmoke"Width="280"Height="190"HorizontalAlignment="Right"Filter="All Files (*.*)|*.*|Image Files|*.tif;*.jpg;*.gif;*.png;*.bmp|Text Files (.txt)|*.txt"FilterIndex="1"Multiselect="True"UploadFailed="attachmentEditor_UploadFailed"></esri:AttachmentEditor></StackPanel></Grid><ProgressBarx:Name="MyProgressBar"IsIndeterminate="True"VerticalAlignment="Bottom"Width="200"Height="20"Margin="10"Visibility="{Binding Path=IsBusy, Converter={StaticResource BooleanToVisibilityConverter}}"></ProgressBar></Grid></UserControl>
using System;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using ESRI.ArcGIS.Client;
using ESRI.ArcGIS.Client.Local;
using System.ComponentModel;
namespace ArcGISWPFSDK
{
publicpartialclass LocalToolkitAttachmentEditor : UserControl, INotifyPropertyChanged
{
publicevent PropertyChangedEventHandler PropertyChanged;
privatebool _isBusy = true;
publicbool IsBusy
{
get
{
return _isBusy;
}
set
{
_isBusy = value;
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs("IsBusy"));
}
}
}
private ArcGISLocalFeatureLayer localfeatureLayer;
public LocalToolkitAttachmentEditor()
{
InitializeComponent();
localfeatureLayer = MyMap.Layers[1] as ArcGISLocalFeatureLayer;
DataContext = this;
MyMap.Layers.LayersInitialized += (o, evt) =>
{
IsBusy = false;
};
}
privatevoid LocalFeatureLayer_Initialized(object sender, EventArgs e)
{
if (localfeatureLayer != null)
localfeatureLayer.MouseLeftButtonUp += LocalFeatureLayer_MouseLeftButtonUp;
}
privatevoid LocalFeatureLayer_MouseLeftButtonUp(object sender, GraphicMouseButtonEventArgs e)
{
for (int i = 0; i < localfeatureLayer.SelectionCount; i++)
localfeatureLayer.SelectedGraphics.ToList()[i].UnSelect();
e.Graphic.Select();
attachmentEditor.GraphicSource = e.Graphic;
}
privatevoid attachmentEditor_UploadFailed(object sender, ESRI.ArcGIS.Client.Toolkit.AttachmentEditor.UploadFailedEventArgs e)
{
MessageBox.Show(e.Result.Message);
}
privatevoid MyMap_Loaded(object sender, RoutedEventArgs e)
{
attachmentEditor.FeatureLayer = localfeatureLayer;
}
}
}
Imports System.Linq
Imports System.Windows
Imports System.Windows.Controls
Imports ESRI.ArcGIS.Client
Imports ESRI.ArcGIS.Client.Geometry
Imports ESRI.ArcGIS.Client.Local
Imports System.ComponentModel
Namespace ArcGISWPFSDK
PartialPublicClass LocalToolkitAttachmentEditor
Inherits UserControl
Implements INotifyPropertyChanged
PublicEvent PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
Private _isBusy AsBoolean = TruePublicProperty IsBusy() AsBooleanGetReturn _isBusy
EndGetSet(value AsBoolean)
_isBusy = value
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs("IsBusy"))
EndSetEndPropertyPrivate localfeatureLayer As ArcGISLocalFeatureLayer
PublicSubNew()
InitializeComponent()
localfeatureLayer = TryCast(MyMap.Layers(1), ArcGISLocalFeatureLayer)
AddHandler MyMap.Layers.LayersInitialized, AddressOf map_LayersInitialized
EndSubPrivateSub map_LayersInitialized(sender AsObject, e As EventArgs)
DataContext = Me
IsBusy = FalseEndSubPrivateSub LocalFeatureLayer_Initialized(sender AsObject, e As EventArgs)
If localfeatureLayer IsNotNothingThenAddHandler localfeatureLayer.MouseLeftButtonUp, AddressOf LocalFeatureLayer_MouseLeftButtonUp
EndIfEndSubPrivateSub LocalFeatureLayer_MouseLeftButtonUp(sender AsObject, e As GraphicMouseButtonEventArgs)
For i AsInteger = 0 To localfeatureLayer.SelectionCount - 1
localfeatureLayer.SelectedGraphics.ToList()(i).UnSelect()
Next
e.Graphic.[Select]()
attachmentEditor.GraphicSource = e.Graphic
EndSubPrivateSub attachmentEditor_UploadFailed(sender AsObject, e As ESRI.ArcGIS.Client.Toolkit.AttachmentEditor.UploadFailedEventArgs)
MessageBox.Show(e.Result.Message)
EndSubPrivateSub MyMap_Loaded(sender AsObject, e As RoutedEventArgs)
attachmentEditor.FeatureLayer = localfeatureLayer
EndSubEndClassEndNamespace