The process of building custom applications and tools that interact with Microsoft SharePoint, including SharePoint Online in Microsoft 365.
Hi @SvenGlöckner ,
web.GetFileByUrl doesn't work with share link. The url should be like https://contoso.sharepoint.com/sites/abc/document/test.txt. If you want to access share link. Please try following code.
var uri = $"https://xxx.sharepoint.com/:i:/s/blah/funkyShareurlhere?e=somestuffhere&download=1";
var handler = new HttpClientHandler {AllowAutoRedirect = false, UseCookies = true};
while (true)
{
var request = new HttpRequestMessage(HttpMethod.Post, uri);
var response = new HttpClient(handler).SendAsync(request).ConfigureAwait(false).GetAwaiter().GetResult();
var statusCode = (int) response.StatusCode;
if (statusCode >= 300 && statusCode <= 399)
{
var redirectUri = response.Headers.Location;
if (!redirectUri.IsAbsoluteUri)
{
redirectUri = new Uri(request.RequestUri.GetLeftPart(UriPartial.Authority) + redirectUri);
}
uri = redirectUri.AbsoluteUri;
continue;
}
if (response.IsSuccessStatusCode)
{
var data = response.Content.ReadAsStreamAsync().GetAwaiter().GetResult();
}
}
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.