teamssharepoint list all files - Stack Overflow

admin2025-04-29  1

We use teams - and it has the ability to create and store files. There are files attached to various group things and in different "teams folders" - or what ever teams calls these things.

Files are "everywhere" - and finding files are impossible, we have duplicate files because people don't know one already exists elsewhere.

My question:

Is there a way to create a list of all files in teams, in all groups - and provide some type of path (location information) to the files.

One of our IT people suggested: use the sharepoint/onedrive - link from the desktop.

That does not work, it lists 2 files for me, I think I created these I want all - nearly 100 files, soon to be THOUSANDS of files.

I am a developer type - so I am looking for a script in any language that I can use to get this data - So - if I have to iterate across each group, or each "sub-team" - that is ok, but I need access to some API and script example to do this. or a place to start with this non-sense.

my goal - is to setup an automatic tool (every 30 minutes?) that regenerates an HTML file with an Index of all sharepoint/teams files present.

as a very simple example, create a CSV file like this: If I need a special "admin rights" - tell me the name, I will obtain this. Then my script should in a nested loop:

  For each TEAMS GROUP NAME
       For each FILE in that group
         Print to a text file (or CSV file I do not care)
         The GROUP name - and subgroupnames (aka: the directory path?)
         The filename
         nice to have: Date/time/LastModifier - etc.

If run against our system - it should provide me with several thousand files. And it needs to be scriptable in any language.

We use teams - and it has the ability to create and store files. There are files attached to various group things and in different "teams folders" - or what ever teams calls these things.

Files are "everywhere" - and finding files are impossible, we have duplicate files because people don't know one already exists elsewhere.

My question:

Is there a way to create a list of all files in teams, in all groups - and provide some type of path (location information) to the files.

One of our IT people suggested: use the sharepoint/onedrive - link from the desktop.

That does not work, it lists 2 files for me, I think I created these I want all - nearly 100 files, soon to be THOUSANDS of files.

I am a developer type - so I am looking for a script in any language that I can use to get this data - So - if I have to iterate across each group, or each "sub-team" - that is ok, but I need access to some API and script example to do this. or a place to start with this non-sense.

my goal - is to setup an automatic tool (every 30 minutes?) that regenerates an HTML file with an Index of all sharepoint/teams files present.

as a very simple example, create a CSV file like this: If I need a special "admin rights" - tell me the name, I will obtain this. Then my script should in a nested loop:

  For each TEAMS GROUP NAME
       For each FILE in that group
         Print to a text file (or CSV file I do not care)
         The GROUP name - and subgroupnames (aka: the directory path?)
         The filename
         nice to have: Date/time/LastModifier - etc.

If run against our system - it should provide me with several thousand files. And it needs to be scriptable in any language.

Share Improve this question asked Jan 7 at 2:58 user3696153user3696153 7507 silver badges16 bronze badges 2
  • Teams file storage is SharePoint. In Teams there is a button to view the files in native SharePoint instead of the Teams interface. -- Users not finding files and creating duplicate files is not a problem specific to Teams. It can happen anywhere untrained people are let loose to store files. Your issue is not about programming but about the lack of guidance that users can follow and training to ensure users know how / where to store files. You may start with yourself and learn about how Teams/SharePoint deals with files, channels, groups, etc. – teylyn Commented Jan 7 at 3:55
  • yes it is true but under linux i can use the find command and create a list of files. and i can do a recursive directory walk on windows but how do i do that with share point. – user3696153 Commented Jan 7 at 4:25
Add a comment  | 

1 Answer 1

Reset to default 0

I used C# with Microsoft.Graph v5

DriveItem currentItem = await _graphClient.Drives[driveId].Root.GetAsync();
if (currentItem == null)
{
    Log.Error("Item was null, when trying to get root path");
    return null;
}

Log.Information("Root item retrieved successfully, id: {id}", currentItem.Id);
for (int i = 1; i < pathSegments.Length; i++)
{
    var segment = pathSegments[i];
    Log.Information("Parsing segment {i}: {segment}", i, segment);

var children = await _graphClient.Drives[driveId].Items[currentItem.Id].Children.GetAsync();


if (children == null || children.Value == null)
{
    Log.Error("Could not find children at this level. Segment {segment}, currentItemId: {currentItemId}", segment, currentItem.Id);
    return null;
}
Log.Information("Children Items Retrieved with {count} children. Item names: {items}", children.Value.Count, string.Join(", ", children.Value.Select(x => x.Name)));

......

转载请注明原文地址:http://anycun.com/QandA/1745934304a91328.html