Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enumerate files/folders from a Teams Channel #843

Closed
1 task done
timdelavoorde opened this issue May 6, 2022 · 3 comments
Closed
1 task done

Enumerate files/folders from a Teams Channel #843

timdelavoorde opened this issue May 6, 2022 · 3 comments
Assignees
Labels
area: model 📐 Related to the core SDK models question Further information is requested

Comments

@timdelavoorde
Copy link

Category

  • Feature request

Describe the feature

Currently it is impossible to load the files or folders that are created under a Teams channel. It is also impossible to create new folders or files

Describe the solution you'd like

I'd like to load the files or folders under a team channel by using channel.LoadAsync(f => f.Files) and channel.LoadAsync(f => f.Folders) respectively.

Additional context

N/A

@jansenbe jansenbe self-assigned this May 6, 2022
@jansenbe jansenbe added question Further information is requested area: model 📐 Related to the core SDK models labels May 6, 2022
@jansenbe
Copy link
Contributor

jansenbe commented May 6, 2022

Hey @timdelavoorde , files and folders in a Teams channel actually live in the default document library of the SharePoint site connected to the Team, by default the default folder is the "Shared Documents" folder and each channel has it's own folder in that library (the channel displayname). So using below approach you can get to the folder hosting the files for the channel:

var team = await context.Team.GetAsync(o => o.Channels);

var folder = await context.Web.GetFolderByServerRelativeUrlAsync($"{context.Uri.PathAndQuery}/Shared Documents/{team.Channels.AsRequested().First().DisplayName}", p=>p.Files);

foreach(var file in folder.Files.AsRequested())
{
  // Use the file
}

Once you've a reference to the IFolder and it's IFileCollection you can also add files, download files, create sub folders etc. See https://pnp.github.io/pnpcore/using-the-sdk/files-intro.html#adding-files-uploading and https://pnp.github.io/pnpcore/using-the-sdk/files-intro.html#downloading-files for more details on that.

I do agree that having a method on ITeamChannel that returns the correct IFolder would be handy, something we'll consider adding.

jansenbe added a commit that referenced this issue May 6, 2022
…ccess point to the SharePoint File capabilities starting from a Team channel #843
@jansenbe
Copy link
Contributor

jansenbe commented May 6, 2022

@timdelavoorde , already created a solution for this. From tomorrow's build you can use the GetFilesFolder methods: this method will use the Graph API to request the driveItemId of the connected folder and then will return you the equivalent IFolder enabling you to use all the file management capabilities of SharePoint.

var team = await context.Team.GetAsync(o => o.Channels);
var folder = await team.Channels.AsRequested().First().GetFilesFolderAsync(p => p.Files);

@jansenbe
Copy link
Contributor

jansenbe commented May 6, 2022

Docs have been added. Closing this issue now. @timdelavoorde : if you still have issues using the new method with tomorrow's nightly build then please reopen this issue or create a new one.

@jansenbe jansenbe closed this as completed May 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: model 📐 Related to the core SDK models question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants