[英]How to get document preview image using SharePoint CSOM
我想以編程方式從 SharePoint 檢索文檔的縮略圖。 我正在嘗試做的是以下內容:
document.GetImagePreviewUrl(width, height, clientType);
這只是返回一個空的ClientResult
。 我不確定要輸入什么作為clientType
值。
我還嘗試以編程方式使用此方法(通過使用WebClient
並下載文件)。 但這只會返回403
響應。
我在這里看到的可能解決方案如下:
clientType
並以這種方式檢索預覽 url。WebClient
和標頭)。我確實需要關於這兩個選項的一些幫助,我不確定從哪里開始,因為這兩個選項都沒有很好的記錄。
我想出了一種方法來做到這一點, 403
錯誤是因為 sharepoint 不知道我是誰。 經過一些研究和擺弄,我發現您發送到預覽頁面的請求包含一個身份驗證 cookie。 這個cookie可以通過使用這段代碼的代碼生成:
// Create an authentication cookie which we can send with the request so sharepoint knows who we are.
var authCookie = credentials.GetAuthenticationCookie(new Uri(imageUrl));
client.Headers.Add(HttpRequestHeader.Cookie, authCookie);
// Download the image data to a byte array
image = client.DownloadData(imageUrl);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.