无法从 C# 和图形资源管理器中的 Sharepoint 图形获取驱动器项目和驱动器文件夹
Posted
技术标签:
【中文标题】无法从 C# 和图形资源管理器中的 Sharepoint 图形获取驱动器项目和驱动器文件夹【英文标题】:Failing to getting Drive items and Drive Folders from Sharepoint Graph in C# and Graph Explorer 【发布时间】:2019-11-07 10:16:34 【问题描述】:我在使用 Graph Drive 项目时遇到了一些问题。我正在尝试访问具有特定结构的文件以读取、写入和更新文件夹中的文件。问题是我无法访问潜在客户文件夹地图,我在 C# 和 Graph Explorer 中尝试了不同的可能性。
文件夹结构 ► MySite.sharepoint.com ► MyUnderSite ► MainDriveFlder ► CustomerDriveFolder ► Driveitems
和
MySite ► MyUnderSite ► MainDriveFlder ► DriveItems
MySite = 站点/CustomerSitename.sharepoint.com: MyUnderSite = 站点/CustomerSitename.sharepoint.com:/sites/CustomerSitename2: MainDriveFlder = Customer_Files CustomerDriveFolder = CustomerNr1_Files Driveitems = word.docs 或 pic.png 或 exel.xlsx
我尝试了什么
在 C# 中
graphserviceClient.Sites["MySite.sharepoint.com:/sites/MyUnderSite:"].Drives.Request().GetAsync();
graphserviceClient.Sites["MySite.sharepoint.com:/sites/MyUnderSite:"].Drives[""].Request().GetAsync();
https://graph.microsoft.com/v1.0/drives/drive-id/root/children
graphserviceClient.Sites["MySite.sharepoint.com:/sites/MyUnderSite:"].Drives["Customer_Files"].Root.Children.Request().GetAsync();
https://graph.microsoft.com/v1.0/sites/tenant.sharepoint.com:path-to-site(ie: /sites/HR):/drives
graphserviceClient.Sites["MySite.sharepoint.com:/sites/MyUnderSite:"].Drives.Request().GetAsync();
https://graph.microsoft.com/v1.0/drives/drive-id/root:/folder-name/file-name.txt:/content
graphserviceClient.Sites["MySite.sharepoint.com:/sites/MyUnderSite:"].Drives["Customer_Files"].Items["ID"].Request().GetAsync();
https://graph.microsoft.com/v1.0/drives/drive-id/root:/folder-name:/children https://graph.microsoft.com/v1.0/me/drive/root/children
图形浏览器 这行得通,我得到了回应 https://graph.microsoft.com/v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drives
然后,我收到一个文件名 = "name": "Customer_Files" 的响应,即 "driveType": "documentLibrary"
但是当我进一步进入这个文件夹或想从中调用项目时,我无法访问它们,C# 同样的问题。 尽管没有正确的 URL 规范,但我已经尝试了所有这些并且没有对错误做出响应。(我尝试过的部分)
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drive/items/Testfiledrive
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drive/items/customer_files
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drive/items/customer
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drive/items/Customer
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drives
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drives/Customer_Files
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drives
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drives
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drives/'Customer_Files'
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drives/"Customer_Files"
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drives/Customer_Files
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drives/Customer_Files:
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drives/Customer_Files
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drives/Customer:
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drives/Customer
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drives
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drives/Customer_Files Export
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drives
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drives/root
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drives
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drive/root/search(q='Customer_Files')
GET /v1.0/me/drive/root/search(q='Customer_files')
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drive/special/documents
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drives/Documents
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drive/Documents
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drive/Documents
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drive/Shared%20Documents
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drives/Shared%20Documents
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drives/Customer_Files:/root/children
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drives/Customer_Files/root/children
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drive/items/Customer_files/children
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drive/items/Customer_files
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drives/Customer_files/items
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drives/Customer_files:
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drives/root
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drives/b!iDg2xo9-yUSnkkcTcFXBP_aUL9EMu9JIqr1aGCz8KH9m3E7rhgkqRLyqeK93F96_
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drives/Customer
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drives/Customer_Files:
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drives/Customer_Files
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drives
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drive/root
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drive/list
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drive/items
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drive/items/
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drive/items/Customer_Files
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drive
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:/drive/items
GET /v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite:
GET /v1.0/me/drive/root/children
GET /v1.0/me/drives/Customer_files
所以主要问题是我无法访问或调用 Customer_Files 和 Customer_Files/Customernr1_Files 中的文件。
谁能帮助我在 c# 和图形资源管理器中找到正确的结构。访问这些文件。 如果我提供的信息有误或信息较少,请告诉我。我已经找了好几个星期了。
我无法提供所有信息并更改一些代号以保护 客户。
【问题讨论】:
【参考方案1】:根据您的结构,我无法判断您的“MyUnderSite”是“MySite”的子网站还是其他网站集。
我将分析这两种情况。
“MyUnderSite”是一个网站集:
-
致电
GET
https://graph.microsoft.com/v1.0/sites/MySite.sharepoint.com:/sites/MyUnderSite
获取“MyUnderSite”的 id。
致电GET https://graph.microsoft.com/v1.0/sites/id of
"MyUnderSite"/drive/root:/customer_files
。
“MyUnderSite”是一个子网站:
致电GET
https://graph.microsoft.com/v1.0/sites/MySite.sharepoint.com/sites
列出子站点并找到“MyUnderSite”的 id。
致电GET https://graph.microsoft.com/v1.0/sites/id of
"MyUnderSite"/drive/root:/customer_files
。
【讨论】:
谢谢!你回答它真的帮助我前进,现在我找到了解决方案。我正在尝试纯名称 ID,但从未尝试使用项目和驱动项/文件夹的原始 ID。我将通过解决方案更新我的问题。我发现。也许它会再次帮助人们解决同样的问题,Allen Wu。 @BEvilM 我很高兴知道我的回答很有帮助。您可以发布您的最终解决方案作为帮助更多人的答案:)【参考方案2】:解决方案
var returnitem = await graphserviceClient.Sites["Site-ID"].Drives["Dive-ID"].Root.Children.Request().GetAsync();//gets all Children in the drive
var returnitemfiles = await graphserviceClient.Sites["Site-ID"].Drives["Drive-ID"].Items["File-ID"].Children.Request().GetAsync();//gets one Child and returns all the Children of that file
var returnitemfile = await graphserviceClient.Sites["Site-ID"].Drives["Dive-ID"].Items["File-ID"].ItemWithPath(fileBase.FileName).Content.Request().PutAsync<DriveItem>(fileBase.InputStream);//upload a file to the drive in a folder by id only usable for small files under 4 MB
Site-ID 可能看起来像这样 = "c6669213-7e4f-44c9-a792-65737055c13f"
潜水 ID ="b!iDh2xo8-yUSnkkcTcFXBP_aUL5EMu9JIqr1aGCz2KH9m3E7rhgkqRLyqiK93Z96_"
文件夹 ID = "01BPZAU2WZBX5ZT55GHTCYVV3WZERIWJM6"
FileBase 我使用了 HttpPostedFileBase
【讨论】:
以上是关于无法从 C# 和图形资源管理器中的 Sharepoint 图形获取驱动器项目和驱动器文件夹的主要内容,如果未能解决你的问题,请参考以下文章
如何使用 Visual Studio 中的 C# 代码打开和关闭与服务器资源管理器中保存的数据库 (.db) 数据连接的连接?
使用 VBA 从 Access 运行后从任务管理器中删除 Excel 任务