Skip to content

jincod/smartsheet-csharp-sdk

 
 

Repository files navigation

NuGet

Smartsheet SDK for C#

This is a C# SDK to simplify connecting to the Smartsheet API from .NET applications.

System Requirements

The SDK supports C# version 4.0 or later running on .NET platform version 4.0 or later. In addition, we support any .NET language compatible with that platform version.

Installation

The SDK can be installed by using NuGet or by compiling from source. These two alternatives are outlined below.

Install with NuGet

If unfamiliar with NuGet, please take a look at the NuGet documentation.

To install the SDK in Visual Studio, right click the References for the project and select Manage NuGet Packages.

Select the Browse or Online tab (depending upon the version of Visual Studio) then type smartsheet in the search box. Select smartsheet-csharp-sdk in the search results and click the Install button.

After clicking Install, you will be asked to accept the License (Apache). Then it will install the Smartsheet SDK and the dependencies (RestSharp, Newtonsoft.Json, and NLog) by adding these libraries to the References section of the project.

You can also use the following command in the Package Manager Console to install the SDK:

Install-Package smartsheet-csharp-sdk

Compile From Source

You can download and compile the source code for the SDK from Github. Use git to fetch it and use Visual Studio or a program such as MSBuild to build it.

In Visual Studio you can open the entire solution with the file Smartsheet-csharp-sdk.sln, or open the specific project Smartsheet-csharp-sdk.csproj.

You can also do this via the command line with the following three commands. Note: The path to msbuild may vary.

git clone https://github.com/smartsheet-platform/smartsheet-csharp-sdk.git
cd smartsheet-csharp-sdk
%WINDIR%\Microsoft.NET\Framework\v4.0.30319\msbuild smartsheet-csharp-sdk.sln /property:Configuration=release /t:rebuild

Documentation

The full Smartsheet API documentation is here: http://smartsheet-platform.github.io/api-docs/?csharp#.

The generated SDK class documentation is here: http://smartsheet-platform.github.io/smartsheet-csharp-sdk/.

Example Usage

To call the API, you will need an access token, which looks something like this example: ll352u9jujauoqz4gstvsae05. You can find the access token in the UI at Account > Personal Settings > API Access.

The following is a brief sample that shows you how to:

  • Initialize the client
  • List all sheets
  • Load one sheet
using Smartsheet.Api;
using Smartsheet.Api.Models;

static void Sample()
{
    // Initialize client
    SmartsheetClient ss = new SmartsheetBuilder()
        // TODO: Set your API access in environment variable SMARTSHEET_ACCESS_TOKEN or else here
        // .SetAccessToken("ll352u9jujauoqz4gstvsae05")
        .Build();

    // List all sheets
    PaginatedResult<Sheet> sheets = ss.SheetResources.ListSheets(
        null,               // IEnumerable<SheetInclusion> includes
        null,               // PaginationParameters
        null                // Nullable<DateTime> modifiedSince = null
    );
    Console.WriteLine("Found " + sheets.TotalCount + " sheets");

    long sheetId = (long) sheets.Data[0].Id;                // Default to first sheet

    // sheetId = 567034672138842;                         // TODO: Uncomment if you wish to read a specific sheet

    Console.WriteLine("Loading sheet id: " + sheetId);

    // Load the entire sheet
    var sheet = ss.SheetResources.GetSheet(
        5670346721388420,           // long sheetId
        null,                       // IEnumerable<SheetLevelInclusion> includes
        null,                       // IEnumerable<SheetLevelExclusion> excludes
        null,                       // IEnumerable<long> rowIds
        null,                       // IEnumerable<int> rowNumbers
        null,                       // IEnumerable<long> columnIds
        null,                       // Nullable<long> pageSize
        null                        // Nullable<long> page
    );
    Console.WriteLine("Loaded " + sheet.Rows.Count + " rows from sheet: " + sheet.Name);
}

A simple, but complete sample application project is here: https://github.com/smartsheet-samples/csharp-read-write-sheet

Contributing

If you would like to contribute a change to the SDK, please fork a branch and then submit a pull request. More info here.

Support

If you have any questions or issues with this SDK please post on StackOverflow using the tag "smartsheet-api" or contact us directly at api@smartsheet.com.

Releases

All releases and release notes are available on Github or the NuGet repository.

About

Library that uses C# to connect to Smartsheet services.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 99.8%
  • Other 0.2%