\u003ccode\u003eusing\u0020(ClientContext\u0020context\u0020=\u0020new\u0020ClientContext("\u0022https:\u002F\u002Fyour-sharepoint-site-url\u0022"))\n{\n\u0020\u0020Web\u0020web\u0020=\u0020context.Web;\n\u0020\u0020Folder\u0020folder\u0020=\u0020web.GetFolderByServerRelativeUrl("\u002Fsites\u002Fyour-site-name\u002FShared\u0020Documents\u002FFolderName");\n\u0020\u0020context.Load(folder);\n\u0020\u0020context.ExecuteQuery();\n\n\u0020\u0020if\u0020(folder\u0020!=\u0020null)\n\u0020\u0020{\n\u0020\u0020\u0020\u0020FileCollection\u0020files\u0020=\u0020folder.Files;\n\u0020\u0020\u0020\u0020context.Load(files);\n\u0020\u0020\u0020\u0020context.ExecuteQuery();\n\n\u0020\u0020\u0020\u0020foreach\u0020(File\u0020file\u0020in\u0020files)\n\u0020\u0020\u0020\u0020{\n\u0020\u0020\u0020\u0020\u0020\u0020Console.WriteLine(file.Name);\n\u0020\u0020\u0020\u0020}\n\u0020\u0020}\n}\n\u003c\u002Fcode\u003e\n\n请确保将 "https:\u002F\u002Fyour-sharepoint-site-url" 替换为你的 SharePoint 网站的 URL,将 "/sites\u002Fyour-site-name\u002FShared\u0020Documents\u002FFolderName" 替换为你要获取元素的文件夹的相对 URL。在上述示例中,我们将文件夹路径设置为“Shared\u0020Documents\u002FFolderName”。\n\n使用 context.Load()context.ExecuteQuery() 方法来加载和执行查询。在查询执行后,你可以遍历 FileCollection 对象并访问每个文件的属性,例如文件名。\n\n请注意,你需要添加所需的命名空间和引用来使用 SharePoint 的客户端对象模型。

SharePoint GetFolderByServerRelativeUrl 获取文件夹所有元素 - 代码示例

原文地址: https://www.cveoy.top/t/topic/p8d0 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录