How to block download for SharePoint in CSOM

Occasional Visitor

Hello, I'm building an automated process that will set share conditions for each file in a specific folder. I want to make this to save me a lot of time doing the process manually for each and every file. I've managed to set expiry link that will disallow editing, but I can't find the function that will block the download. (For the button at the bottom on the image below).



Here is the code for my project so far, if the function exists, how would I implement it into the code below?


static void Main(string[] args)
    string siteUrl = "";
    SecureString password = new SecureString();
    foreach (char c in "password".ToCharArray()) password.AppendChar(c);
    using (var cc = new AuthenticationManager().GetSharePointOnlineAuthenticatedContextTenant(siteUrl, "username", password))
        string folderUrl = @" Documents/TestFolder";
        Uri folderUri = new Uri(folderUrl);
        Folder folder = cc.Web.GetFolderByServerRelativeUrl(folderUri.AbsolutePath);
        bool isEdit = false;
        DateTime five_days = DateTime.Now.AddDays(14);
        ClientResult<String> anonExpEditLink = Web.CreateAnonymousLinkWithExpiration(cc, folderUrl, isEdit, five_days.ToString("yyyy-MM-ddThh:mm:ssZ"));
        string anonExpEditLink2 = cc.Web.CreateAnonymousLinkWithExpirationForDocument(folderUrl, ExternalSharingDocumentOption.Edit, five_days);
        FileCollection fileCol = folder.Files;
        foreach (File file in fileCol)

Any help would be appreciated, thank you.

0 Replies