How to find folder id for existing smartsheet
All,
I am trying to create and maintain a bunch of smartsheets using the API. I would like to find an existing smartsheet to use as a template and create new smartsheets based on the source sheet and in the same folder as the source sheet.
I have code to locate the source smartsheet as shown below. I can find the sheet no problem, however, the folderID of the found sheet is null. How can I locate the folder the sheet that I found is located in?
Here is the code to find the existing smartsheet. Is there a way to find the folder of this sheet?
// Get all the sheets this user can see... PaginatedResult<Sheet> sheets = smartsheetClient.SheetResources.ListSheets( new List<SheetInclusion> { SheetInclusion.SHEET_VERSION }, new PaginationParameters( true, null,null ), null ); log.Debug( "Found " + sheets.TotalCount + " sheets" ); // Loop through all the sheets and find the matching passed in sheet name int sheetIndex = 0; while( sheetIndex < sheets.TotalCount ) { long aSheetID = (long)sheets.Data[sheetIndex].Id; aSheet = smartsheetClient.SheetResources.GetSheet( aSheetID, null, null, null, null, null, null, null ); log.Debug( "Processing Sheet: " + aSheet.Name + " - " + aSheet.GetType() ); if( aSheet.Name.Equals( aSheetNameToLocate, StringComparison.OrdinalIgnoreCase ) ) { log.Debug( "Found Sheet: " + aSheet.Name + " - " + aSheet.GetType() ); foundSheet = true; break; } sheetIndex++; }
Answers
-
There isn't a direct way to find the folder from the information returned about a specific sheet: the only way to get the folder ID is to start by finding the workspace ID (which is present when the sheet object is returned).
Then you can call the API to get the workspace, which gives a breakdown of folders and the sheets in each folder (see here). You'll need to cross-match against this to find your matching sheet ID by looping through.
Note: if you use the
loadAll
flag when getting the workspace, then it will include all folders and subfolders as well.Cheers,
Genevieve
Need more help? 👀 | Help and Learning Center
こんにちは (Konnichiwa), Hallo, Hola, Bonjour, Olá, Ciao! 👋 | Global Discussions
-
Hello
This may work when the sheet is in a workspace. But what about when the sheet is not in a workspace, in a subfolder of your "sheets" folder?
sheet.workspace returns None in this scenario
-
Can you provide a sample code of doing so? The link you posted is no longer valid and it redirect to general doc
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
- 141 Just for fun
- 58 Community Job Board
- 462 Show & Tell
- 32 Member Spotlight
- 1 SmartStories
- 299 Events
- 38 Webinars
- 7.3K Forum Archives