FRAMES | NO FRAMES
UploadTable Method

Uploads an external data in tabular form into the repository.

Availability: Business Analyst Server.

void UploadTable ( 
    string  WorkspaceName, 
    string  ProjectName, 
    string  ItemName, 
    string  FileUrl, 
    bool    OverwriteAll 
); 

Parameter Description
WorkspaceName Workspace name. Type String.
ProjectName Project name. Type String.
ItemName Name of project item to save data table as. Type String.
FileUrl URL to a table already uploaded to ArcGIS Server virtual output directory. Type String.
OverwriteAll Overwrite any existing content. Type Boolean.

Remarks

The upload process consists of two steps. At the first step, you should upload a table in some way to the ArcGIS Server virtual output directory. At the last step, you can upload this table to an item of the Custom Data folder of the Business Analyst Server repository using this method.

The following table formats are supported:

Examples

The example below uploads an Excel spreadsheet from a client to the Business Analyst Server Repository. This example assumes you have an Excel spreadsheet accessed at "C:\Data\customers.xls" and containing the following information:

To download this table, click the link below or right click this link and choose "Save as..." in the pop-up menu.

Download the customers.xls table

C#
// Instantiate the BAServerHelper class to access analysis methods
BAServerHelper baServerHelper = new BAServerHelper();
 
string localPath = @"C:\Data\customers.xls"; // Local path to the table
 
// ========= STEP 1: Upload the table 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();
 
// We replace this extension with the extension of the uploaded file.
url = url.Substring(0, url.Length - 4) + System.IO.Path.GetExtension(localPath);
 
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 table to the Business Analyst Server Repository
 
string project = "Default Project";
string workspace = "Default Workspace";
string itemName = "customers";
bool overwriteAll = true;
 
baServerHelper.UploadTable(workspace, project, itemName, url, overwriteAll);

See Also