FRAMES | NO FRAMES
UploadShapefile Method

Uploads a shapefile into the repository.

Availability: Business Analyst Server 9.3.1.

void UploadShapefile ( 
    string                     ShapefileZIP, 
    ShapefileFolderParameters  ShapefileFolderParameters, 
    esriFolderItem             OutputItem, 
    UploadShapefileParameters  ShapefileParameters 
);

Parameter Description
ShapefileZIP URL to a shapefile zip-archive already uploaded to ArcGIS Server virtual output directory. Type String.
ShapefileFolderParameters Shapefile folder parameters. Type ShapefileFolderParameters. This parameter is not intended to be used in a client code.
OutputItem Folder item to upload the shapefile to. Type esriFolderItem.
ShapefileParameters Shapefile parameters. Type UploadShapefileParameters.

Remarks

The upload process consists of two steps. At the first step, you should upload in some way a zip-archive with shapefile files to the ArcGIS Server virtual output directory. At the last step, you can upload the contents of this archive to an item of the Business Analyst Server repository using this method.

Examples

The example below uploads a local shapefile to the Business Analyst Server Repository. This example assumes you have a compressed shapefile folder accessed at "C:\Data\shapefile.zip". After execution, this shapefile is available as a trade area layer of the Default Project of the Default Workspace of the repository.

To download a sample shapefile.zip archive, click the link below or right click this link and choose "Save as..." in the pop-up menu.

Download the shapefile.zip archive

C#
// Instantiate the BAServerHelper class to access analysis methods
BAServerHelper baServerHelper = new BAServerHelper();
 
string localPath = @"C:\Data\shapefile.zip"; // Local path to the shapefile
 
// ========= STEP 1: Upload the shapefile to the ArcGIS Server output directory
 
// Get an URL to a unique filename at the ArcGIS Server output directory.
// This filename contains a unique GUID and has the ".zip" extension.
string url = baServerHelper.GetUniqueFileName();
 
using (System.IO.FileStream output = System.IO.File.OpenRead(localPath))
{
    // Prepare a web request for uploading the file
    System.Net.WebRequest request = System.Net.HttpWebRequest.Create(url);
    request.Method = System.Net.WebRequestMethods.Http.Put;
    request.ContentLength = output.Length;
    request.ContentType = "application/x-www-form-urlencoded";
    request.Credentials = System.Net.CredentialCache.DefaultCredentials;
    request.Timeout = 300000; // 300,000 milliseconds (5 minutes)
 
    // Send the file to the server
    using (System.IO.Stream requestStream = request.GetRequestStream())
    {
        byte[] buffer = new byte[1024];
        int count;
        while ((count = output.Read(buffer, 0, buffer.Length)) > 0)
            requestStream.Write(buffer, 0, count);
    }
    request.GetResponse(); // This operation completes the request
}
 
// ========= STEP 2: Upload the shapefile to the Business Analyst Server Repository
 
esriFolderItem item = new esriFolderItem();
item.folderType = esriFolderType.esriFolderTradeAreas;
item.itemName = "tradeArea_UploadShapefile";
item.workspaceName = "Default Workspace";
item.projectName = "Default Project";
 
UploadShapefileParameters parameters = new UploadShapefileParameters();
parameters.DescriptionFieldName = "AREA_DESC";
parameters.SymbolizationFieldName = "RING";
 
baServerHelper.UploadShapefile(url, item, parameters);

See Also