Click or drag to resize
CsvLayerServiceUri Property
ServiceUri is the location to the CSV file.

Namespace: Esri.ArcGISRuntime.Layers
Assembly: Esri.ArcGISRuntime (in Esri.ArcGISRuntime.dll) Version: 10.2.7.0 (10.2.7.1234)
Syntax
public string ServiceUri { get; set; }

Property Value

Type: String
Remarks

The source of a .csv file can be served up on a web server as a service or locally on disk. If the .csv file is on a web server, the typical format for the string of the ServiceUri Property would be the http:// format (ex: "http://www.mywebserver.com/Cities.csv"). If the .csv file is on the local disk, the typical format for the string of the ServiceURI Property would be the absolute full path/filename format (ex: "C:\Data\Cities.csv") or relative filename (ex: "Cities.csv" or "..\Cities.csv"). Another alternative for accessing a .csv file can be done via a System.IO.Stream that is set via the CsvLayer.SetSourceAsync Method.

NOTE: Assuming that a .csv file follows the normal conventions of using a comma for the column separator and uses X and Y field names like: X/Y, lat/long, latitude/longitude, etc. it is insufficient for a CsvLayer to display in the map by just setting either the .ServiceUri Property or .SetSourceAsync Method. It is mandatory to create symbology and add it to a Renderer and then set that to the CsvLayer.Renderer Property in order for the CsvLayer to display in the map.

Examples

Demonstrates creating a CsvLayer by performing a Drag-and-Drop from a file on the local disk in File Explorer to the MapView.

Using Drag-and-Drop to copy a .csv file from the File Explorer to the MapView.

XAML
<Window x:Class="MapView_DragDropEvents.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="600" Width="800"
    xmlns:esri="http://schemas.esri.com/arcgis/runtime/2013">

    <Grid x:Name="LayoutRoot">

        <!-- Define a SimpleRenderer with a SimpleMarkerSymbol that will be used the symbology for a CsvLayer 
        added via code-behind. -->
        <Grid.Resources>
            <esri:SimpleRenderer x:Key="mySimpleRenderer">
                <esri:SimpleRenderer.Symbol>
                    <esri:SimpleMarkerSymbol Color="Red" Style="Circle" Size="12"/>
                </esri:SimpleRenderer.Symbol>
            </esri:SimpleRenderer>
        </Grid.Resources>

        <StackPanel Orientation="Vertical">

            <!-- TextBlock to provide the instructions on how to use the sample code. It will be 
                populated with instructions in the code-behind when the application loads. -->
            <TextBlock Height="81" HorizontalAlignment="Left" Name="TextBlock1" VerticalAlignment="Top" 
                           Width="770" TextWrapping="Wrap"  Margin="10,2,0,0" />

            <StackPanel Orientation="Horizontal">

                <!-- Add a MapView Control. Enable the Events of DragEnter, DrageLeave, and Drop. This will 
                allow a user to Drag-and-Drop a .csv file from the File Explorer on disk into the MapView and 
                have it display as a CsvLayer. Whenever you use the various Drag-and-Drop events, it is necessary 
                to set the AllowDrop Property to be True. -->
                <esri:MapView x:Name="MapView1" Width="600" Height="480" VerticalAlignment="Top" Margin="2,2,2,2"
                              DragEnter="MapView1_DragEnter" DragLeave="MapView1_DragLeave"  Drop="MapView1_Drop" 
                              AllowDrop="True" >

                    <!-- A Map. Set the initial extent (via the InitialViewpoint Property) to be the continental US. -->
                    <esri:Map  x:Name="Map1" InitialViewpoint="-15219969,2609636,-6232883,6485365">

                        <!-- Add a backdrop ArcGISTiledMapServiceLayer-->
                        <esri:ArcGISTiledMapServiceLayer ID="World_Topo_Map" 
                      ServiceUri="http://services.arcgisonline.com/arcgis/rest/services/world_topo_map/MapServer" />
                    </esri:Map>

                </esri:MapView>

                <!-- Add some controls to allow the user to see when the various Drag-and-Drop Events have fired. -->
                <StackPanel Orientation="Vertical">
                    <Label Content="DragDrop Events:" FontSize="14"/>
                    <TextBlock x:Name="TextBlockDragDropEvents" Width="187" Height="456"/>
                </StackPanel>

            </StackPanel>
        </StackPanel>
    </Grid>

</Window>

SPECIAL NOTE: The XAML displayed above comes from a C# project. If you are a VB.NET developer, you will need to modify the text for the x:Class namespace from "MapView_DragDropEvents.MainWindow" to be just "MainWindow".

// INSTRUCTIONS:
// 
// (1) Copy the following ASCII text into Notepad and save the file as C:\TestData\Cities.csv:
// ID,Lat,Long,CityName,Population
// 1,40.714,-74.006,New York City,8244910
// 2,34.0522,-118.244,Los Angeles,3819702
// 3,41.878,-87.636,Chicago,2708120
// 4,29.763,-95.363,Houston,2099451
// 5,39.952,-75.168,Philadelphia,1526006
// 6,29.423,-98.493,San Antonio,1327407
// 7,32.715,-117.156,San Diego,1326179
// 8,32.782,-96.815,Dallas,1223229
// 9,37.228,-119.228,San Jose,945942
// 10,30.331,-81.655,Jacksonville,821784
// 
// (2) Copy the following ASCII text into Notepad and save the file as C:\TestData\Garbage.bad:
// BLAH BLAH BLAH.
// THIS FILE CONTAINS GARBAGE.
// 
// (3) Run the application and following the instructions in the TextBox.

namespace MapView_DragDropEvents
{
    public partial class MainWindow : System.Windows.Window
    {
        public MainWindow()
        {
            InitializeComponent();

            // Add the instructions on how to use this example code to the TextBlock.
            TextBlock1.Text = "Open a File Explorer window and navigate to the C:\\TestData directory. Drag the Garbage.bad file onto the MapView Control and then " + 
                "drag it back to the File Explorer window (don't drop the Garbage.bad file onto the MapView at this point). You should see the several event messages " + 
                "display in the TextBlockDragDropEvents control. Then drag the Cities.csv file onto the MapView Control and drop it onto the MapView Control. You " + 
                "should see CsvLayer graphics added to the Map for the top 10 largest cities in the US.";
        }

        private void MapView1_DragEnter(object sender, System.Windows.DragEventArgs e)
        {
            // Display to the user that the MapView.DrageEnter Event has fired.
            TextBlockDragDropEvents.Text = TextBlockDragDropEvents.Text + "DragEnter occurred" + System.Environment.NewLine;

            // Get the name of the file that is being dragged from the File Explorer into the MapView Control. Use the exact string: "FileNameW" as the parameter 
            // of the e.Data.GetData Method to obtain the full path/filename of the file being dragged from the File Explorer to the MapView. The actual return 
            // value from the e.Data.GetData Method is an Array of String. Some starter reference materials for Drag-and-Drop can be found in the following documents: 
            // "How To: Add a Drag-and-Drop Handler" (by Microsoft): http://msdn.microsoft.com/en-us/library/ff793459.aspx 
            // "Enable Your Windows Forms Applications to Drag-and-Drop Data Objects" (non Microsoft): http://www.codemag.com/Article/0407031
            string[] myObject = (string[])e.Data.GetData("FileNameW", true);

            if (myObject != null)
            {
                // Because the myObject is an Array of Strings, get the first element in the array, this will be full path/filename of the file being dragged from the File Explorer.
                string fullpath = (string)myObject[0];

                // Determine the file extension of the file being dragged into the MapView.
                if (fullpath.EndsWith(".csv"))
                {
                    // We have a .csv file. Let the user know this is a valid type that can be dropped into the MapView.
                    TextBlockDragDropEvents.Text = TextBlockDragDropEvents.Text + "Valid File Type" + System.Environment.NewLine;
                }
                else
                {
                    // We have some unknown file type. Notify the user this is not an acceptable file type that can be dropped into the MapView.
                    TextBlockDragDropEvents.Text = TextBlockDragDropEvents.Text + "Not Valid File Type" + System.Environment.NewLine;
                }
            }
        }

        private void MapView1_DragLeave(object sender, System.Windows.DragEventArgs e)
        {
            // Inform the user that the use left the MapView with a Dragged item from the File Explorer. NOTE: the MapView.Drop Event is not fired
            // if you drag the item out of the MapView. 
            TextBlockDragDropEvents.Text = TextBlockDragDropEvents.Text + "DragLeave occurred" + System.Environment.NewLine + System.Environment.NewLine;
        }

        private void MapView1_Drop(object sender, System.Windows.DragEventArgs e)
        {
            // Inform the user they have dropped the item from the File Explorer into the MapView.  NOTE: this does not mean that the item will automatically be
            // added to the MapView. In this code example, we will only be adding .csv files as CSVLayer objects into the MapView.
            TextBlockDragDropEvents.Text = TextBlockDragDropEvents.Text + "Drop occurred" + System.Environment.NewLine;

            // Get the object (Array of String) that has the path/filename of the file that is being dragged from the File Explorer into the MapView Control.
            string[] myObject = (string[])e.Data.GetData("FileNameW", true);

            if (myObject != null)
            {
                // Because the myObject is an Array of String, get the first element in the array, this will be full path/filename of the file being dragged from the File Explorer.
                string fullpath = myObject[0];

                // Determine the file extension ends with a ".csv".
                if (fullpath.EndsWith(".csv"))
                {
                    // Create a CsvLayer. 
                    Esri.ArcGISRuntime.Layers.CsvLayer myCsvLayer = new Esri.ArcGISRuntime.Layers.CsvLayer();

                    // Set the ServiceUri Property to the path/filename of the .csv file on local disk. 
                    myCsvLayer.ServiceUri = fullpath;

                    // Set the ID of the CsvLayer.
                    myCsvLayer.ID = "US_Cities_Top_5";

                    // Get a SimpleRenderer that was defined in XAML and apply it to the CsvLayer. NOTE: it is imperative that a Renderer be set on the 
                    // CsvLayer or else no visual elements will be drawn in the Map.
                    myCsvLayer.Renderer = LayoutRoot.Resources["mySimpleRenderer"] as Esri.ArcGISRuntime.Symbology.SimpleRenderer;

                    // Add the CsvLayer to the Map.
                    MapView1.Map.Layers.Add(myCsvLayer);

                    // Add an ending linefeed/carriage return to make the output format look more readable if multiple Drag-and-Drop operations are performed.
                    TextBlockDragDropEvents.Text = TextBlockDragDropEvents.Text + System.Environment.NewLine;
                }
            }
        }    

    }
}
See Also
Supported Platforms
This type is supported on the following ArcGIS Runtime .NET SDK platforms:
Windows Desktop
Windows Phone
Windows Store
Additional Examples
Hyperlink to ExampleDescription
CSVLayerXamlDemonstrates defining a CsvLayer in XAML and setting the serviceUri property to a text file hosted online by the United States Geological Survey (USGS).
MapView_DragDropEventsDemonstrates creating a CsvLayer by performing a Drag-and-Drop from a file on the local disk in File Explorer to the MapView.