Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我是否可以更新SharePoint文档';使用Microsoft Graph的元数据?_Sharepoint_Microsoft Graph Api_Metadata - Fatal编程技术网

我是否可以更新SharePoint文档';使用Microsoft Graph的元数据?

我是否可以更新SharePoint文档';使用Microsoft Graph的元数据?,sharepoint,microsoft-graph-api,metadata,Sharepoint,Microsoft Graph Api,Metadata,我正在使用Graph在SharePoint中创建文件夹和文档,但不知道如何更新文档的元数据。也许不可能,我似乎找不到任何细节 我在Json消息中尝试了一个带有元数据的补丁命令,但没有成功 我可以使用此代码创建文件,这样我的身份验证就可以了 public static string UploadContent(string webApiUrl, string accessToken, byte[] data) { string s = String.Empty;

我正在使用Graph在SharePoint中创建文件夹和文档,但不知道如何更新文档的元数据。也许不可能,我似乎找不到任何细节

我在Json消息中尝试了一个带有元数据的补丁命令,但没有成功

我可以使用此代码创建文件,这样我的身份验证就可以了

    public static string UploadContent(string webApiUrl, string accessToken, byte[] data)
    {
        string s = String.Empty;
        if (!string.IsNullOrEmpty(accessToken))
        {
            using (var client = new WebClient())
            {
                client.Headers.Add(HttpRequestHeader.Accept, "application/json");
                client.Headers.Add(HttpRequestHeader.Authorization, accessToken);
                s = client.Encoding.GetString(client.UploadData(webApiUrl, "PUT", data));

            }
        }

        return s;
    }
上传文件后,需要利用文件更新listItem上的属性,例如:

a) 上载文件:

PUT  https://graph.microsoft.com/v1.0/drives/{drive-id}/root:/{file-path}:/content
Body: file content
b) 更新列表项:

PATCH https://graph.microsoft.com/v1.0/drives/{drive-id}/root:/{file-path}:/listItem/fields   
Content-Type: application/json
Body {
    "Title": "new title"
}
C#示例

using (var client = new System.Net.WebClient())
{
    client.BaseAddress = "https://graph.microsoft.com/";
    client.Headers.Add(HttpRequestHeader.Accept, "application/json");
    client.Headers.Add(HttpRequestHeader.Authorization, accessToken);

    //1.Upload a new file
    var requestUrl = $"/v1.0/drives/{driveId}/root:/{filePath}:/content";
    var result = client.UploadData(requestUrl, "PUT", contentBytes);

    //2.Set file metadata
    requestUrl = $"/v1.0/drives/{driveId}/root:/{filePath}:/listItem/fields";
    var fields = new { Title = "Sample video" };
    var fieldsPayload = JsonConvert.SerializeObject(fields);
    client.Headers.Add(HttpRequestHeader.ContentType, "application/json");
    client.UploadString(requestUrl, "PATCH", fieldsPayload);

}