Welcome to the Smartsheet Forum Archives
The posts in this forum are no longer monitored for accuracy and their content may no longer be current. If there's a discussion here that interests you and you'd like to find (or create) a more current version, please Visit the Current Forums.
c# Form submitting row to sheet via API 2.0.x
I am using our website to submit froms to Smartsheet and am having dificulty following the C# explanations in the API documentation. The first is a simple form with Date Submitted, First Name, Last Name and Email (formulated Date, Text/Number, Text/Number, Text/Number respectively). I have not even added the variables in but Visual Studio is not recognizing sheetId (sqiggly red underscore in last line). Anyone know how to rectify this?
Comments
-
Michael,
C# is Casesensitive. Try sheetID in stead of sheetId. Exactly as you defined it earlier.
-
Just to recap: We had moved to the API 2 and we are using the following code to submit a single row via the codebehind in C#. (we had also installed smartsheet-csharp-sdk as a NuGet Solution in Visual Studio)
protected void SendRowToSmartsheet() {
string smartsheetAPIToken = ConfigurationManager.AppSettings["SWTCSmartsheetToken"];
Token token = new Token();
token.AccessToken = smartsheetAPIToken;
// Use the Smartsheet Builder to create an instance of SmartsheetClient
SmartsheetClient smartsheet = new SmartsheetBuilder().SetAccessToken(token.AccessToken).Build();
// Get all columns (omit 'include' parameter and pagination parameters).
smartsheet.SheetResources.ColumnResources.ListColumns(73123464072xxxxx, null, null);
// Specify cell values for first row.
Cell[] cellsA = new Cell[] {
new Cell.AddCellBuilder(17217962705xxxxx, DateTime.Now).Build(),
new Cell.AddCellBuilder(2653362358xxxxx, name.Text).Build(),
new Cell.AddCellBuilder(73338073857xxxxx, whomComplaint.Text).Build(),
new Cell.AddCellBuilder(73338073857xxxxx, phone.Text).Build(),
new Cell.AddCellBuilder(17043078515xxxxx, email.Text).Build(),
new Cell.AddCellBuilder(84597072926xxxxx, issue.Text).Build()
};
// Specify contents of first row.
Row rowA = new Row.AddRowBuilder(true, null, null, null, null).SetCells(cellsA).Build();
// Add rows to sheet.
smartsheet.SheetResources.RowResources.AddRows(73123464072xxxxx, new Row[] {rowA
});
} -
** nevermind** this works fine. Just make sure you haven't added, oh, hundreds of blank rows first.
-
How can add multiple rows at a time.Right now with
smartSheets.SheetResources.RowResources.AddRows(Id, new Row[] { rowsToUpdate });, I can only add a single row at a time to the sheet.If I have a list of rows how do I add it?
-
i am looking for a similar sample too (add multiple rows). If anyone has something to share would be highly appreciated
If i come up with a better solution i will update this post at a later time
-
You can enter in many rows if needed, and even add rows to multiple sheets!
Once you've added the first row:
Cell[] cellsA = new Cell[] {
//new Cell.AddCellBuilder(5149002225xxxxx, DateTime.Now).Build(),
new Cell.AddCellBuilder(289720241xxxxx, name.Text).Build(),
new Cell.AddCellBuilder(740080203xxxxx, phone.Text).Build(),
new Cell.AddCellBuilder(177130250xxxxx, email.Text).Build(),
new Cell.AddCellBuilder(852670194xxxxx, message.Text).Build()
};
// Specify contents of first row.
Row rowA = new Row.AddRowBuilder(true, null, null, null, null).SetCells(cellsA).Build();
// Add rows to sheet.
smartsheet.SheetResources.RowResources.AddRows(2729671298xxxxx, new Row[] {rowA});You can add others (and even use variables for the column and sheet IDs):
Cell[] cellsB = new Cell[] {
//new Cell.AddCellBuilder(DateTimeID, DateTime.Now).Build(),
new Cell.AddCellBuilder(nameID, name.Text).Build(),
new Cell.AddCellBuilder(phoneID, phone.Text).Build(),
new Cell.AddCellBuilder(emailID, email.Text).Build(),
new Cell.AddCellBuilder(messageID, message.Text).Build()
};
// Specify contents of first row.
Row rowB = new Row.AddRowBuilder(true, null, null, null, null).SetCells(cellsB).Build();
// Add rows to sheet.
smartsheet.SheetResources.RowResources.AddRows(sheetID, new Row[] { rowB });We used a case statement above our putting together rowB, C, D, ... to declare the different column and sheet IDs.
Mike
-
You could also set this up in a loop for entering in multiple rows. You would just iterate through an array setting the variables to the next group of data and submitting to the sheet.
-
If you have your data in an array, you could use a while loop to iterate through the array and submit multiple rows to the sheet that way. I replied to the previous comment about a way to submit multiple rows.
Categories
- All Categories
- 14 Welcome to the Community
- Smartsheet Customer Resources
- 64.2K Get Help
- 419 Global Discussions
- 221 Industry Talk
- 461 Announcements
- 4.8K Ideas & Feature Requests
- 143 Brandfolder
- 142 Just for fun
- 58 Community Job Board
- 462 Show & Tell
- 32 Member Spotlight
- 1 SmartStories
- 299 Events
- 38 Webinars
- 7.3K Forum Archives