简体   繁体   English

循环浏览 Sharepoint (Teams) 文件夹中的文件

[英]Loop through files in Sharepoint (Teams) folder

I'm trying to loop through all files in a Teams SharePoint folder, but I cannot get the FileSystemObject to recognize the address.我正在尝试遍历 Teams SharePoint 文件夹中的所有文件,但我无法让 FileSystemObject 识别地址。 First, I tried using the copy link for the folder in teams and then using this:首先,我尝试使用团队中文件夹的复制链接,然后使用:

Dim fso As New FileSystemObject
Dim fldr As Folder: Set fldr = fso.GetFolder("address for sharepoint folder copied above")

But it always tells me it can't find it.但它总是告诉我找不到它。 I also tried something very similar for exact files in that folder Dim fl As File: Set fl = fso.GetFile("address") but still wouldn't work我还为该文件夹中的确切文件尝试了非常相似的方法Dim fl As File: Set fl = fso.GetFile("address")但仍然无法正常工作

Then I googled and found this link: Get the content of a sharepoint folder with Excel VBA but it still errors on oNetwork.MapNetworkDrive DriveLetter & ":", NetworkPath when trying to find that location.然后我用谷歌搜索并找到了这个链接: Get the content of a sharepoint folder with Excel VBA但它仍然在oNetwork.MapNetworkDrive DriveLetter & ":", NetworkPath找到那个位置时出错。

I also tried replacing the / with \ and removing the https: but still no good.我还尝试将 / 替换为 \ 并删除 https: 但仍然不行。 I've also tried getting the link from within Teams and within SharePoint.我还尝试从 Teams 和 SharePoint 中获取链接。 Still can't find it.还是找不到。 If I put an Excel file in that folder and tell excel to open it with Application.Workbooks.Open("address") that will open an excel file.如果我将 Excel 文件放在该文件夹中并告诉 excel 使用Application.Workbooks.Open("address")打开它,它将打开一个 excel 文件。 But I just can't get the Dir or FileSystemObject to recognize the address.但我就是无法让 Dir 或 FileSystemObject 识别地址。 I'm suspicious it might have something to do with not using the correct address but for the life of me I can't find another address link in SharePoint.我怀疑这可能与没有使用正确的地址有关,但对于我的一生,我在 SharePoint 中找不到另一个地址链接。 I'd really appreciate any help someone can give me.我真的很感激有人可以给我的任何帮助。

I'm specifically trying to do this in MS Access but also tested in Excel with the same results.我专门尝试在 MS Access 中执行此操作,但也在 Excel 中进行了测试,结果相同。

What you're trying to do would probably have worked in some situations for on premises SharePoint, as it would probably have used the very old WebDav protocol under the covers, but it's not possible/applicable for SharePoint Online (the cloud SharePoint that powers Teams) and you should user the modern Microsoft 365 approach to doing this. What you're trying to do would probably have worked in some situations for on premises SharePoint, as it would probably have used the very old WebDav protocol under the covers, but it's not possible/applicable for SharePoint Online (the cloud SharePoint that powers Teams ) 并且您应该使用现代 Microsoft 365 方法来执行此操作。 It's definitely more work, especially because there's increased security when you're in the cloud (which is a good thing), but it means there's a learning curve around this.这肯定是更多的工作,特别是因为当你在云中时安全性得到了提高(这是一件好事),但这意味着有一个学习曲线。

Essentially, the main API for anything Microsoft cloud is the Microsoft Graph.从本质上讲,Microsoft 云的主要 API 是 Microsoft Graph。 Specifically, for getting files you want to work with Drives and DriveItems (an abstraction around both SharePoint and OneDrive, depending on where the file(s) live).具体来说,为了获取您想要使用 Drives 和 DriveItems 的文件(围绕 SharePoint 和 OneDrive 的抽象,具体取决于文件所在的位置)。 Here is a good starting point for you: https://docs.microsoft.com/en-us/graph/api/resources/onedrive?view=graph-rest-1.0这是一个很好的起点: https://docs.microsoft.com/en-us/graph/api/resources/onedrive?view=graph-rest-1.0

This also looks relevant: https://docs.microsoft.com/en-us/graph/api/channel-get-filesfolder?view=graph-rest-1.0&tabs=http这看起来也很相关: https://docs.microsoft.com/en-us/graph/api/channel-get-filesfolder?view=graph-rest-1.0&tabs=http

But of course you also need some background in using Graph, authenticating, etc., so see here: https://docs.microsoft.com/en-us/graph/overview?view=graph-rest-1.0 .但当然,您还需要一些使用 Graph、身份验证等方面的背景知识,因此请参见此处: https://docs.microsoft.com/en-us/graph/overview?view=graph-rest-1.0 The security context you need will depend on whether you're running on behalf of a user (eg when the user is in a tab in Teams), which is called 'delegated' permissions, or whether you have a background service/process running (like a weekly process doing something), which would required 'application' permissions.您需要的安全上下文取决于您是否代表用户运行(例如,当用户在 Teams 的选项卡中时),这称为“委托”权限,或者您是否有后台服务/进程正在运行(就像每周做某事的过程一样),这需要“应用程序”权限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM