获取属于特定组的工作表
Get sheets belonging to a specific group
如何判断 sheet 是否属于某个组?
例如,我们有一个名为 RPR 的群组,当我们创建 sheet 时,我们会与组织中的其他用户共享它们,将群组应用到 sheet。
// Get all sheets modified within last day
SmartSheetList = smartsheet
.SheetResources
.ListSheets(new SheetInclusion[] { SheetInclusion.OWNER_INFO }, new PaginationParameters(true, null, null))
.Data
.Where(d => d.ModifiedAt.Value.Date >= DateTime.Now.AddDays(-1).Date)
.ToList();
// Get organization sheets
var orgUserSheets = smartsheet.UserResources.SheetResources.ListSheets(true).Data.ToList();
// get specific group
var group = smartsheet.GroupResources.ListGroups(null).Data.Where(grp => grp.Id == some-id-here).First();
通过上面的代码,我可以看到 sheet 是否属于某个组织,但我无法判断 sheet 是否属于某个组。任何帮助将不胜感激。
每个 sheet 还需要一个 API 请求来检索 sheet 上的共享列表。请记住,sheet 可以直接在 sheet 上或通过工作区共享。
要获取直接或通过工作区与特定组共享的 sheets,您可以使用类似于下面的代码(此示例依赖于 LINQ)。
SmartsheetClient cl = new SmartsheetBuilder()
.SetAccessToken(ACCESS_TOKEN)
.Build();
var includeAll = new PaginationParameters(true, null, null);
Console.WriteLine("Looking for group " + SOUGHT_GROUP_NAME);
var groups = cl.GroupResources.ListGroups(includeAll);
var soughtGroup = groups.Data.Single((group) => group.Name == SOUGHT_GROUP_NAME);
Console.WriteLine("Found group ID {0} for group {1}.", soughtGroup != null ? soughtGroup.Id.ToString() : "NULL", SOUGHT_GROUP_NAME);
if (soughtGroup == null)
throw new ArgumentException("Group not found");
var sheets = cl.SheetResources.ListSheets(null, includeAll);
Console.WriteLine("Querying through {0} sheets...", sheets.Data.Count);
var sheetsSharedWithGroup = from sheet in sheets.Data
from share in cl.SheetResources.ShareResources.ListShares(sheet.Id.Value, includeAll, ShareScope.Workspace).Data
where share.GroupId == soughtGroup.Id
select new { Sheet = sheet, Share = share };
var found = sheetsSharedWithGroup.ToList();
Console.WriteLine("Found {0} sheets shared with group {1}.", found.Count, SOUGHT_GROUP_NAME);
found.ForEach(foundSheet => Console.WriteLine("Sheet {0} shared with {1} ({2})", foundSheet.Sheet.Name, foundSheet.Share.Name, foundSheet.Share.Type));
注意:我提交 a pull request 以添加对 returns 工作区共享的特定 ListShares 重载的支持。这在 REST API 中可用,但在 C# SDK 中尚不可用。
注意:以上代码没有考虑 Smartsheet Sights yet. It should be possible using the corresponding REST API for Sights (i.e. List Sights, List Sight Shares,但我认为 C# SDK 中还没有。
如何判断 sheet 是否属于某个组?
例如,我们有一个名为 RPR 的群组,当我们创建 sheet 时,我们会与组织中的其他用户共享它们,将群组应用到 sheet。
// Get all sheets modified within last day
SmartSheetList = smartsheet
.SheetResources
.ListSheets(new SheetInclusion[] { SheetInclusion.OWNER_INFO }, new PaginationParameters(true, null, null))
.Data
.Where(d => d.ModifiedAt.Value.Date >= DateTime.Now.AddDays(-1).Date)
.ToList();
// Get organization sheets
var orgUserSheets = smartsheet.UserResources.SheetResources.ListSheets(true).Data.ToList();
// get specific group
var group = smartsheet.GroupResources.ListGroups(null).Data.Where(grp => grp.Id == some-id-here).First();
通过上面的代码,我可以看到 sheet 是否属于某个组织,但我无法判断 sheet 是否属于某个组。任何帮助将不胜感激。
每个 sheet 还需要一个 API 请求来检索 sheet 上的共享列表。请记住,sheet 可以直接在 sheet 上或通过工作区共享。
要获取直接或通过工作区与特定组共享的 sheets,您可以使用类似于下面的代码(此示例依赖于 LINQ)。
SmartsheetClient cl = new SmartsheetBuilder()
.SetAccessToken(ACCESS_TOKEN)
.Build();
var includeAll = new PaginationParameters(true, null, null);
Console.WriteLine("Looking for group " + SOUGHT_GROUP_NAME);
var groups = cl.GroupResources.ListGroups(includeAll);
var soughtGroup = groups.Data.Single((group) => group.Name == SOUGHT_GROUP_NAME);
Console.WriteLine("Found group ID {0} for group {1}.", soughtGroup != null ? soughtGroup.Id.ToString() : "NULL", SOUGHT_GROUP_NAME);
if (soughtGroup == null)
throw new ArgumentException("Group not found");
var sheets = cl.SheetResources.ListSheets(null, includeAll);
Console.WriteLine("Querying through {0} sheets...", sheets.Data.Count);
var sheetsSharedWithGroup = from sheet in sheets.Data
from share in cl.SheetResources.ShareResources.ListShares(sheet.Id.Value, includeAll, ShareScope.Workspace).Data
where share.GroupId == soughtGroup.Id
select new { Sheet = sheet, Share = share };
var found = sheetsSharedWithGroup.ToList();
Console.WriteLine("Found {0} sheets shared with group {1}.", found.Count, SOUGHT_GROUP_NAME);
found.ForEach(foundSheet => Console.WriteLine("Sheet {0} shared with {1} ({2})", foundSheet.Sheet.Name, foundSheet.Share.Name, foundSheet.Share.Type));
注意:我提交 a pull request 以添加对 returns 工作区共享的特定 ListShares 重载的支持。这在 REST API 中可用,但在 C# SDK 中尚不可用。
注意:以上代码没有考虑 Smartsheet Sights yet. It should be possible using the corresponding REST API for Sights (i.e. List Sights, List Sight Shares,但我认为 C# SDK 中还没有。