Replace a Data Table

Replace the contents of an existing table with a CSV or Excel file.

šŸ‘

Permissions Required

You must have Edit permissions to the data table for this request to succeed

Method Signature

DataTable Replace(string id, FileInfo file, int headerRow = 1, int sheetNumber = 1);
async Task<DataTable> ReplaceAsync(string id, FileInfo file, int headerRow = 1, int sheetNumber = 1);

Parameters

ParameterTypeDescription
idstringThe Id of the Data Table whose contents will be replaced
fileFileInfoThe File to upload. Must be a CSV, XLS or XLSX file
headerRowintOptional The index of row containing column headers.
Row counting starts at 1.
sheetNumberintOptional The index of the worksheet to import for Excel files.
Sheet counting starts at 1. Defaults to 1.
returnsDataTableThe updated Data Table
DataTable Replace(Guid id, FileInfo file, int headerRow = 1, int sheetNumber = 1);
async Task<DataTable> ReplaceAsync(Guid id, FileInfo file, int headerRow = 1, int sheetNumber = 1);
ParameterTypeDescription
idGuidThe Id of the Data Table whose contents will be replaced
fileFileInfoThe File to upload. Must be a CSV, XLS or XLSX file
headerRowintOptional The index of row containing column headers.
Row counting starts at 1.
sheetNumberintOptional The index of the worksheet to import for Excel files.
Sheet counting starts at 1. Defaults to 1.
returnsDataTableThe updated Data Table

Example

/*
 * This example demonstrates replacing a Data Table in Cataltyic
 * with a file.
 */
using System.IO;

namespace Catalytic.Sdk.Examples
{
    class Program
    {
        static void Main(string[] args)
        {
            var catalytic = new Catalytic.Sdk.CatalyticClient(Credentials.Default);

            // create a file to upload
            var file = new FileInfo(Path.GetTempFileName());
            var csv = "\"Name\",\"Age\"\n\"Alice\",\"42\"\n\"Bob\",\"54\"";

            File.WriteAllText(file.FullName, csv);
            var existingTableId = "10000000-0000-0000-0000-000000000001";

            // upload the file
            var result = catalytic.DataTable.Replace(existingTableId, file);
        }
    }
}