我正在使用phpSPO库,以便在PHP应用程序中使用sharePoint。https://github.com/vgrem/phpSPO
我使用以下代码在Sharepoint上的Shared Documents文件夹中成功创建了一个文件夹:
<?php
spl_autoload_register(function ($classname) {
$classname = ltrim($classname, "\");
preg_match('/^(.+)?([^\\]+)$/U', $classname, $match);
$classname = './'.str_replace("\", "/", $match[1])
.str_replace(array("\", "_"), "/", $match[2])
.".php";
include_once $classname;
});
use Office365RuntimeAuthClientCredential;
use Office365SharePointClientContext;
use Office365SharePointWeb;
$credentials = new ClientCredential("MyClientId", "MyClientSecret");
$ctx = (new ClientContext("https://MyDomain.sharepoint.com"))->withCredentials($credentials);
$folderName = "TestFolder_" . rand(1, 100000);
$rootFolder = $ctx->getWeb()->getFolderByServerRelativeUrl("Shared Documents");
$newFolder = $rootFolder->getFolders()->add($folderName)->executeQuery();
print($newFolder->getServerRelativeUrl());
>
这将在"共享文档"文件夹中创建文件夹。然而,我的客户创建了一个名为"咨询"的子网站。我不知道如何在子网站的"共享文档"文件夹中创建文件夹。
就我的一生而言,我似乎无法找到一条根路。
我不确定我是否错过了sharepoint的一些基本信息(这是我第一次接触sharepoint(
我如何找到它的路径来添加它?
phpSPO框架中是否有其他方法可以将文件夹添加到特定网站/子网站?
答案(最终(很简单:更改ClientContext以包括站点名称/子站点名称。
在这种情况下,我的子网站被称为"查询"。
<?php
spl_autoload_register(function ($classname) {
$classname = ltrim($classname, "\");
preg_match('/^(.+)?([^\\]+)$/U', $classname, $match);
$classname = './'.str_replace("\", "/", $match[1])
.str_replace(array("\", "_"), "/", $match[2])
.".php";
include_once $classname;
});
use Office365RuntimeAuthClientCredential;
use Office365SharePointClientContext;
use Office365SharePointSiteUrl;
use Office365SharePointWeb;
$credentials = new ClientCredential("MyClientId", "MyClientSecret");
$ctx = (new ClientContext("https://MyDomain.sharepoint.com/enquiries"))->withCredentials($credentials);
$folderName = "Spencer_" . rand(1, 100000);
$rootFolder = $ctx->getWeb()->getFolderByServerRelativeUrl("Shared Documents");
$newFolder = $rootFolder->getFolders()->add($folderName)->executeQuery();
print($newFolder->getServerRelativeUrl());
?>
我一直试图从Root中找到一条相对路径,但总是出错。答案是改变词根。