How to block download for SharePoint in CSOM

Copper Contributor

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).

 

splinkexample.png

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 = "https://company.sharepoint.com.mcas.ms/sites/TestCompany";
    SecureString password = new SecureString();
    foreach (char c in "password".ToCharArray()) password.AppendChar(c);
    
    using (var cc = new AuthenticationManager().GetSharePointOnlineAuthenticatedContextTenant(siteUrl, "username", password))
    {
        string folderUrl = @"https://company.sharepoint.com.mcas.ms/sites/TestCompany/Shared 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);
        cc.ExecuteQuery();
    
        cc.Load(folder.Files);
        cc.ExecuteQuery();
        FileCollection fileCol = folder.Files;
        foreach (File file in fileCol)
        {
            Console.WriteLine(anonExpEditLink.Value);
            Console.WriteLine(anonExpEditLink2);
        }
    }
}

Any help would be appreciated, thank you.

0 Replies