ArcGIS API for Silverlight - Library Reference
AutoSave Property
See Also  Example Send comments on this topic
ESRI.ArcGIS.Client Namespace > FeatureLayer Class : AutoSave Property

Gets or sets the whether edits to the layer's graphics collection are auto-submitted to the service. Default is true.

Syntax

Visual Basic (Declaration) 
Public Property AutoSave As Boolean
C# 
public bool AutoSave {get; set;}

Remarks

In order be able to edit a FeatureLayer you must use a web service coming from an ArcGIS Server FeatureServer.

Example

The following steps show one example workflow for creating a FeatureLayer that is editable from within the client application. The following prerequisites are necessary:

  • It is assumed that the development machine has the following software installed: Visual Studio 2010, ArcMap 10.1 (ArcEditor or ArcInfo), ArcGIS Server 10.1 (Standard or Advanced), ArcSDE 10.1 for SQLServer (Workgroup or Enterprise).

  • For this example, the development machine name is DK-RED2A and the specific SQL Server Instance ID is SQLEXPRESS3 and hence the full name of the SQL Server instance is DK-RED2A\SQLEXPRESS3. Tip: If you forgot the name of your SQL Server instance, you can open the Microsoft SQL Server Management Studio application and when the Connect to Server dialog appears, click the dropdown arrow of the ComboBox for the Server name and choose <Browse for more...>. Then in the Browse for Servers dialog click on either the Local Servers or Network Servers tabs to find the name of your SQL Server instance.

  • A sample polygon shapefile data is necessary to complete the example workflow. The data for this example was obtained from the US Census at the web page: Cartographic Boundary Files. The .zip file gz_2010_us_040_00_20m.zip was downloaded to the directory C:\TestCensusData and unzipped. Once unzipped the exact path to the shapefile is C:\TestCensusData\gz_2010_us_040_00_20m\ gz_2010_us_040_00_20m.shp. Feel free to use any shapefile data that you have if you prefer not to use the sample data from the Census but be warned that the polygon shapefile should be relatively simple in complexity. The more vertices that make up the polygons in the shapefile, the slower will be the feature editing experience in the FeatureLayer. The sample shapefile chosen from the Census for this example has already been generalized to have less verticies and therefore have relatively fast performance when doing feature editing. This is particularly important for completing Step 3.

  • An ArcGIS Server Administrator Connection has been set up to publish web mapping services from ArcGIS Desktop to ArcGIS Server. This will be listed as arcgis on [MY_SERVER] (publisher) node under the GIS Servers of the Catalog Tree dockable window of ArcCatalog. For this example on the development machine named DK-RED2A, the publishing ArcGIS Server Connection in ArcCatalog is entitled arcgis on DK-RED2A_6080 (publisher). If your development machine does not have a publishing ArcGIS Server Connection set up, you can review the ArcGIS 10.1 Help document entitled Making a publisher connection to ArcGIS Server in ArcGIS for Desktop. This document is located in the help folder hierarchy: Services | ArcGIS for Server (Windows) | Administering ArcGIS for Server | Common administrative tasks | Connecting to ArcGIS Server in ArcGIS for Desktop. This is particularly important for completing Step 4.

Step1: Add an ArcSDE Database Server

  • Open ArcCatalog.

  • Double click on the Add Database Server icon in the Catalog Tree dockable window.

    Add a Database Server.

  • In the Add Database Server dialog, specify the name SQL Server instance that you have installed. In this example the SQL Server instance is DK-RED2A\SQLEXPRESS3.

    Specify the SQL Server Instance.

  • This will add the ArcSDE Database Server to Catalog Tree dockable window.

    The newly added Database Server.

Step 2: Create a new Geodatabase

  • Right-click on the new ArcSDE Geodatabase Server (DK-RED2A_SQLEXPRESS.GDS for this example) and choose New Geodatabase... from the context menus.

    Choose create a 'New Geodatabase' from the context menus.

  • In the New Geodatabase dialog, specify the Geodatabase Name in the TextBox. In this example we will specify the name as: MyArcSDEGeodatabaseTest.

    Specify a name for the new Geodatabase.

  • You will see the following information dialog while ArcCatalog is processing to create the new Geodatabase.

    Processing dialog.

  • When completed you will see the new Geodatabase added to your ArcSDE Database Server.

    The newly added GeoDatabase.

Step 3: Populate the Geodatabase with data

  • Right-click on the Geodatabase (MyArcSDEGeodatbaseTest in this example) and choose Import | Feature Class (single)... from the context menus.

    Choose to import a Feature Class from the context menus.

  • When the Feature Class to Feature Class dialog opens, click the Input Feature button.

    Click the Input Features button.

  • When the Input Features dialog opens, navigate to the location of the sample test polygon shapefile and then click the Add button. In this example the shapefile was located at: C:\TestCensusData\gz_2010_us_040_00_20m\ gz_2010_us_040_00_20m.shp.

    Navigate to and add the shapefile in the Input Features dialog.

  • Then in the Feature Class to Feature Class dialog, provide a name in the Output Feature Class TextBox and click the OK button. In this example, the name is: US_States_Census.

    Provide a name for the Output Feature Class.

  • When the ArcCatalog is finished its geoprocessing to add the contents of the shapefile into a Feature Class contained in the Geodatabase, an informational popup titled Feature Class to Feature Class will display on the computer.

    The process of creating the Feature Class is complete.

  • You can then expand the node next to the ArcSDE Geodatabase to see the newly added Feature Class (MyArcSDEGeodatabaseTest.DBO.US_States_Census).

    Viewing the newly added Feature Class in the Geodatabase.

Step 4: Register the ArcSDE Geodatabase (this enables editing using the ArcGIS API for Silverlight)

  • In the Catalog Tree dockable window, expand the GIS Servers node and right-click on the publisher connection (this should have been previously set up, as per the prerequisites) and choose Server Properties... from the context menus. For this example the publishing ArcGIS Server Connection in ArcCatalog is entitled: arcgis on DK-RED2A_6080 (publisher).

    Accessing the Server Properties from the context menus.

  • In the ArcGIS Server Properties dialog that opens click the (+) in the Registered Databases section.

    Click the (+) button in the Registered Dataase section.

  • The Register Database dialog will open. Provide a Name to register the database with the ArcGIS Server. In our example the name used is: DK-RED2A_SQLEXPRESS3. Then click the Add button in the Publisher database connection section.

    Provide a name for the Registered Database and click the Add button.

  • In the Database Connection dialog that opens, provide the name of the SQL Server Instance in the textbox (for this example it is: DK-RED2A\SQLEXPRESS3). Then click the downdown arrow for the Database ComboBox and choose the new Geodatabase added in Step 2 (for this example it is: MyArcSDEGeodatabaseTest), then click OK.

    Provide the SQL Server Instance name and Database in the dialog.

  • Now the Register Database dialog will be fully populated with all the necessary values. Click OK to register the database.

    Click OK to register the database.

  • The ArcGIS Server Properties dialog will again open with the ArcSDE Geodatabase being registered which enables editing of FeatureLayers using the ArcGIS API for Silverlight.

    Confirmation that the database is registered.

Step 5: Create an .mxd document in ArcMap containing the new ArcSDE Geodatabase Feature Class

  • Open ArcMap. If the ArcMap – Getting Started dialog appears click the Cancel button to start a new ArcMap document.

    Start ArcMap and create a new black document.

  • Click the Catalog icon to open the Catalog dockable window. Click the push pin to dock the Catalog window. In the Catalog dockable window, expand the Database Servers node and then the node for the ArcSDE Geodatabase Server (in our case: DK-RED2A_SQLEXPRESS3.gds). Then expand the node for the Geodatabase created in Step 2 (in our case: MyArcSDEGeodatabaseTest (VERSION:dbo:DEFAULT)) and this will reveal the FeatureLayer added in Step 3.

    Open the Catalog dockable window and expand the node to reveal the Feature Class in the Geodatabase.

  • Drag the MyArcSDEGeodatabaseTest.DBO.US_States_Census Feature Class into the Data View and then click the push pin to collapse the Catalog dockable window.

    Drag-n-drop the Geodatabse Feature Class into the Data View of ArcMap.

  • Right-click with the mouse on the MyArcSDEGeodatabaseTest.DBO.US_States_Census Feature Class in the Table of Contents dockable window and choose Properties...from the content menu. When the Layer Properties dialog opens, shorten the Layer Name to: US_States_Census and click the OK button.

    Modify the Layer name inthe Properties dialog.

  • Choose File | Save As and name the map document US_States_Census.mxd.

    Save the ArcMap document.

Step 6: Publish the FeatureLayer map service on ArcGIS Server

  • In ArcMap, choose File | Share As | Service from the menus.

    Choose Share As | Service from the context menus to start the publishing of a editable FeatureLayer map service.

  • When the Share as Service dialog opens keep the default settings and click Next.

    Choose the default (Publish a service) in the Share as Service dialog.

  • In the Publish a Service dialog, keep the default setting and click Next (the service name will be US_States_Census in this example).

    Keep the defaults in the Publish a Service dialog.

  • In the second part of the Publish a Service dialog, accept the defaults and click Continue.

    Keep the defaults in the 2nd part of the Publish a Service dialog.

  • This will launch the Service Editor dialog which is the last phase in publishing a map service on ArcGIS Server.

    The default opening ofthe Service Editor dialog.

  • Click on the Capabilities tab and check on Feature Access to enable the ability to edit features in a FeatureLayer.

    Check on Feature Access in the Capabilities tab.

  • Click on the Item Description tab, and enter values for the Summary, Tags, and Description. In this example these values are:

    • Summary: Generalized US States from the Census
    • Tags: US States Census
    • Description: The US States is an editable FeatureLayer. The data came from the shapefiles from the Census and is generalized to have less vertices for faster response time in the client application

    Enter values for the Summary, Tags, and Description in the Item Description tab.

  • Then click the Publish button, to finish the creating of the editable FeatureLayer map service on ArcGIS Server.

    The Service Publishing Result dialog appears whan the map service have been published.

Step7: Create a Visual Studio project to test the editing capabilities of the FeatureLayer

  • Open Visual Studio and create a project based upon the type of application you will be building (e.g. Silverlight). Add References for the ESRI.ArcGIS.Client and ESRI.ArcGIS.Client.Toolkit Assemblies and any other Assemblies required to run the application.

  • The following screen shot corresponds to executing the example code in Visual Studio. Your example may look different depending on how you use the EditorWidget to modify the FeatureLayer.

    Screen shot of executing the Visual Studio project.

  • Replace the following XAML for the default Grid and add the following code-behind (C# or VB.NET depending on your programming preference) example code in the appropriate location of your Visual Studio project. Then compile and run the application to test FeatureLayer editing capabilities.

XAMLCopy Code
<Grid x:Name="LayoutRoot" >
   
  <!-- Provide the instructions on how to use the sample code. -->
  <TextBlock Height="69" HorizontalAlignment="Left" Name="TextBlock1" VerticalAlignment="Top" Width="612" 
             TextWrapping="Wrap" Text="When the application loads use the Editor Widget to perform various editing 
             functions on the FeatureLayer. For example: try selecting multiple states and unioning them together, 
             try editing the vertices of an existing state to re-shape its boundary, select some states and delete 
             them. After you have made your changes do not forget to click the Save button." />
  
  <!-- Add a Map Control. -->
  <esri:Map Background="White" HorizontalAlignment="Left" Margin="12,172,0,0" Name="Map1" VerticalAlignment="Top" 
            WrapAround="True" Height="400" Width="600">
    <esri:Map.Layers>
      <esri:LayerCollection>
        
        <!--Add a backdrop ArcGISTiledMapServiceLayer-->
        <esri:ArcGISTiledMapServiceLayer ID="World_Street_Map"
              Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer" />
        
        <!-- 
        Add an editable FeatureLayer. Note how the REST endpoint for the Url uses a 'FeatureServer' meanining
        it is editable, and not a 'MapServer' which is read-only. Wire up the FeatureLayer.Initialized Event 
        for use with code-behind functions. 
        -->
        <esri:FeatureLayer ID="US_States_Census" Initialized="FeatureLayer_Initialized" 
              Url="http://dk-red2a:6080/arcgis/rest/services/US_States_Census/FeatureServer/0"/>
        
      </esri:LayerCollection>
    </esri:Map.Layers>
  </esri:Map>
    
  <!-- 
  Add an EditorWidget Control for ease of editing the FeatureLayer. 
  
  The EditorWidget uses Binding on the Map Property associate itself with the Map Control.  
    
  In order to make use of all the features of the EditorWidget you must provide a valid GeometryServiceUrl. If you
  do not specify a valid GeometryServiceUrl the EditorWidget features of Reshape, Union, and Cut features will not
  be available. The GeometryServiceUrl does not need to be hosted on the same machine as where the FeatureLayer web
  service resides. Any public GeometryServiceUrl will do.
    
  See the API documentation for the functionality of the other EdtorWidget Properties like: ShowAttributesOnAdd, 
  AutoSelect, and AlwaysDisplayDefaultTemplates.
  -->
  <esri:EditorWidget HorizontalAlignment="Left" Margin="12,81,0,0" Name="EditorWidget1" VerticalAlignment="Top"
        Map="{Binding ElementName=Map1}" Height="91" Width="596" 
        GeometryServiceUrl="http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer"
        ShowAttributesOnAdd="True" AutoSelect="False" AlwaysDisplayDefaultTemplates="True" />
</Grid>
C#Copy Code
private void FeatureLayer_Initialized(object sender, System.EventArgs e)
{
  // Get the FeatureLayer.
  ESRI.ArcGIS.Client.FeatureLayer theFeatureLayer = (ESRI.ArcGIS.Client.FeatureLayer)sender;
  
  // Because the FeatureLayer.AutoSave Property is turned off, you must click the Save button on the EditorWidget
  // to store the edit changes.
  theFeatureLayer.AutoSave = false;
  
  // Let all of the Attribute Fields in the FeatureLayer be returned. That way the user can edit them with the
  // EditorWidget.
  theFeatureLayer.OutFields.Add("*");
  
  // Retrieve all the features in the FeatureLayer. 
  theFeatureLayer.Mode = ESRI.ArcGIS.Client.FeatureLayer.QueryMode.Snapshot;
  
  // Get the FeatureLayer.ID that was specified in XAML.
  string theFeatureLayerID = theFeatureLayer.ID;
  
  // Pass the FeatureLayer.ID into an Array of Strings.
  string[] myLayerIDs = { theFeatureLayerID };
  
  // Set the EditorWidget.LayerIDs to the Array of Strings. This lets the EditorWidget know which FeatureLayers 
  // can be edited.
  EditorWidget1.LayerIDs = myLayerIDs;
}
VB.NETCopy Code
Private Sub FeatureLayer_Initialized(sender As System.Object, e As System.EventArgs)
  
  ' Get the FeatureLayer.
  Dim theFeatureLayer As ESRI.ArcGIS.Client.FeatureLayer = sender
  
  ' Because the FeatureLayer.AutoSave Property is turned off, you must click the Save button on the EditorWidget
  ' to store the edit changes.
  theFeatureLayer.AutoSave = False
  
  ' Let all of the Attribute Fields in the FeatureLayer be returned. That way the user can edit them with the
  ' EditorWidget.
  theFeatureLayer.OutFields.Add("*")
  
  ' Retrieve all the features in the FeatureLayer. 
  theFeatureLayer.Mode = ESRI.ArcGIS.Client.FeatureLayer.QueryMode.Snapshot
  
  ' Get the FeatureLayer.ID that was specified in XAML.
  Dim theFeatureLayerID As String = theFeatureLayer.ID
  
  ' Pass the FeatureLayer.ID into an Array of Strings.
  Dim myLayerIDs() As String = {theFeatureLayerID}
  
  ' Set the EditorWidget.LayerIDs to the Array of Strings. This lets the EditorWidget know which FeatureLayers 
  ' can be edited.
  EditorWidget1.LayerIDs = myLayerIDs
  
End Sub

Requirements

Target Platforms: Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family, Windows 7

See Also

© ESRI, Inc. All Rights Reserved.