SharePoint et CSharp

De Banane Atomic
Aller à la navigationAller à la recherche

Télécharger un thumbnail de vidéo

Cs.svg
using Microsoft.SharePoint.Client;  // assembly Microsoft.SharePoint.Client.Runtime

const string PWD = "xxx";
const string USER = "me@domain.fr";
var password = new SecureString();
foreach (var c in PWD)
    password.AppendChar(c);
var credential = new SharePointOnlineCredentials(USER, password);

using (var handler = new HttpClientHandler() { Credentials = credential })
{
    //Getting authentication cookies 
    var uri = new Uri("https://site.sharepoint.com");
    handler.CookieContainer.SetCookies(uri, credential.GetAuthenticationCookie(uri));

    //Invoking REST API 
    using (var client = new HttpClient(handler))
    {
        //client.DefaultRequestHeaders.Accept.Clear();
        //client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

        HttpResponseMessage response = await client.GetAsync("https://site.sharepoint.com/portals/Evolve/pVid/video.mp4.PNG?VideoPreview=1").ConfigureAwait(false);
        response.EnsureSuccessStatusCode();

        // enregistrement de l'image dans un fichier
        using (Stream contentStream = await response.Content.ReadAsStreamAsync())
        {
            using (var stream = File.OpenWrite(@"C:\Dossier\image.png"))
            {
                await contentStream.CopyToAsync(stream);
            }
        }
    }
}