Preview
Hi, Visitor  | 

List Files Sample

[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

Description

The List Files sample shows how to retrieve a list of your private shapefiles. Publicly available shapefiles are also included if your subscription plan allows it.

Sample Details

The code in the Browse Code section does the following:
  1. Creates a UriQueryBuilder instance which is used to create a REST Uri with the appropriate inventory parameters.
  2. Creates a RESTHelper instance that provides methods to easily communicate with ShapeServer's REST endpoints.
  3. Retrieves the inventory response of type ShapefileMetaDataCollection.
  4. Displays the file properties by enumerating the received collection.
Note
Replace the [YourApiKey] parameter value with your actual API key.
Note
Depending on your subscription plan you may or may not see public shapefiles included in the results.

Sample Instructions

Prerequisites

To run this sample, you will need to download the .NET SDK for ShapeServer. The SDK contains the assemblies necessary to successfully run the sample. Use Microsoft Visual Studio 2012 (Express) to build and run a sample. To obtain an evaluation copy, go to Visual Studio 2012.

Build the sample

  1. Start Visual Studio 2012 (Express) and select File > New > Project.
  2. In the language of your choice, select Windows and click Console Application.
  3. Enter a name for the sample and click OK to create the project.
  4. In the Solution Explorer window, right-click the References node and select Add reference.
  5. Browse to the location of the ShapeServer SDK files and select the following assemblies:
    • BartelsOnline.ShapeServer.SDK
    • BartelsOnline.ShapeServer.REST.Types
    • BartelsOnline.Shapefiles.Types
  6. Copy the code in the Browse Code section and paste it in the project.
  7. Press F6 or use Build > Build Solution to build the sample.

Run the sample

To debug the sample and then run it, press F5 or use Debug > Start Debugging.
To run the sample without debugging, press Ctrl+F5 or use Debug > Start Without Debugging.

Interactive Sample

There is no interactive sample available for this code.

Browse Code

C#
VB
        
using System;
using BartelsOnline.ShapeServer.SDK.REST;
using BartelsOnline.ShapeServer.REST.Types.Responses;

namespace BartelsOnline.ShapeServer.Samples
{
   class Program
   {
      static void Main(string[] args)
      {
         try
         {
            UriQueryBuilder uriQueryBuilder = new UriQueryBuilder("http://api.shapeserver.com/REST/v1/");
            uriQueryBuilder.Add("key", "[YourApiKey]");
            Uri metaDataUri = uriQueryBuilder.ToUri("shapefiles/inventory");

            RESTHelper helper = new RESTHelper();
            Response response = helper.GetData(metaDataUri);
            ShapefileMetaDataCollection metaDataCollection = (ShapefileMetaDataCollection)response.Resource;

            Console.WriteLine("My file list:");
            foreach (ShapefileMetaData md in metaDataCollection.Shapefiles)
            {
              Console.WriteLine(String.Format("- {0} ({1}): ", md.Name, 
			                                  md.ShapeType) + (md.IsPublicShape ? "public" : "private"));
            }
         }
         catch (Exception exp)
         {
            Console.WriteLine(exp.Message);
         }
         finally
         {
            Console.ReadLine();
         }
      }
   }
}
    

See Also