Reputation: 159
I am trying to read data from Smartsheet using C# SDK. I can get sheet info but column details such as ColumnId are Null.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Smartsheet.Api;
using Smartsheet.Api.Models;
using Smartsheet.Api.OAuth;
namespace SmartSheetTest
{
class Program
{
static void Main(string[] args)
{
string token = "MY_TOKEN";
long sheetid = MY_SHEET_ID;
SmartsheetClient sc = new SmartsheetBuilder().SetAccessToken(token).Build();
Sheet sheet = sc.SheetResources.GetSheet(sheetid, null, null, null, null, null, null, null);
Console.WriteLine("Done");
Console.ReadLine();
}
}
}
The result is below. Only column type and title is filled. Other properties are Null
How can I get column properties?
SDK Version : 2.2.1
Upvotes: 0
Views: 546
Reputation: 289
I know this is very late, but you can iterate through the columns by accessing the sheet.Columns property. I've used it to get the ColumnId and the Title, which is the header string text.
foreach (Column column in sheet.Columns)
Debug.WriteLine(column.Title + " " + column.Id));
Upvotes: 0
Reputation: 13500
Each column within the sheet
object that's populated by the GetSheet
response should always contain a value for the following properties, at a minimum:
It's entirely possible that some of the other properties you're seeing in Debug mode might be null
by design, BUT each and every column
in the response should always contain an Id
property value that you could subsequently use in a GetColumn
request to retrieve all column property values.
I'm unable to reproduce your issue. I've used the code that you've posted (with version 2.2.1 of the Smartsheet C# SDK) to retrieve a Sheet and examine the properties of several columns within the sheet
object that's populated by the GetSheet
response. Regardless of which sheet I retrieve or which column I inspect in Debug mode, the properties listed above are always populated, as shown by this screenshot:
A couple of suggestions for troubleshooting:
Test this scenario using a different sheet. If you CANNOT repro the issue with a different sheet, then perhaps there's something particular about the one sheet that's preventing the Id
attribute from populating in the GetSheet
response.
If you CAN repro this issue with another sheet, then perhaps try testing this same scenario using this sample app: https://github.com/smartsheet-samples/csharp-read-write-sheet. Note -- you'll need to update the Smartsheet C# SDK NuGet package to version 2.2.1 to exactly mimic the scenario you're wanting to test. (I used this sample app in my (unsuccessful) attempt to repro your issue.)
Upvotes: 1