How to block download for SharePoint in CSOM

%3CLINGO-SUB%20id%3D%22lingo-sub-2199299%22%20slang%3D%22en-US%22%3EHow%20to%20block%20download%20for%20SharePoint%20in%20CSOM%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2199299%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%3EHello%2C%20I'm%20building%20an%20automated%20process%20that%20will%20set%20share%20conditions%20for%20each%20file%20in%20a%20specific%20folder.%20I%20want%20to%20make%20this%20to%20save%20me%20a%20lot%20of%20time%20doing%20the%20process%20manually%20for%20each%20and%20every%20file.%20I've%20managed%20to%20set%20expiry%20link%20that%20will%20disallow%20editing%2C%20but%20I%20can't%20find%20the%20function%20that%20will%20block%20the%20download.%20(For%20the%20button%20at%20the%20bottom%20on%20the%20image%20below).%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22splinkexample.png%22%20style%3D%22width%3A%20407px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F262450i9ABBE35B5ACA29A6%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22splinkexample.png%22%20alt%3D%22splinkexample.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3EHere%20is%20the%20code%20for%20my%20project%20so%20far%2C%20if%20the%20function%20exists%2C%20how%20would%20I%20implement%20it%20into%20the%20code%20below%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E%3CSPAN%20class%3D%22hljs-function%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Estatic%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-keyword%22%3Evoid%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-title%22%3EMain%3C%2FSPAN%3E(%3CSPAN%20class%3D%22hljs-params%22%3E%3CSPAN%20class%3D%22hljs-built_in%22%3Estring%3C%2FSPAN%3E%5B%5D%20args%3C%2FSPAN%3E)%3C%2FSPAN%3E%0A%7B%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-built_in%22%3Estring%3C%2FSPAN%3E%20siteUrl%20%3D%20%3CSPAN%20class%3D%22hljs-string%22%3E%22https%3A%2F%2Fcompany.sharepoint.com.mcas.ms%2Fsites%2FTestCompany%22%3C%2FSPAN%3E%3B%0A%20%20%20%20SecureString%20password%20%3D%20%3CSPAN%20class%3D%22hljs-keyword%22%3Enew%3C%2FSPAN%3E%20SecureString()%3B%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Eforeach%3C%2FSPAN%3E%20(%3CSPAN%20class%3D%22hljs-built_in%22%3Echar%3C%2FSPAN%3E%20c%20%3CSPAN%20class%3D%22hljs-keyword%22%3Ein%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-string%22%3E%22password%22%3C%2FSPAN%3E.ToCharArray())%20password.AppendChar(c)%3B%0A%20%20%20%20%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Eusing%3C%2FSPAN%3E%20(%3CSPAN%20class%3D%22hljs-keyword%22%3Evar%3C%2FSPAN%3E%20cc%20%3D%20%3CSPAN%20class%3D%22hljs-keyword%22%3Enew%3C%2FSPAN%3E%20AuthenticationManager().GetSharePointOnlineAuthenticatedContextTenant(siteUrl%2C%20%3CSPAN%20class%3D%22hljs-string%22%3E%22username%22%3C%2FSPAN%3E%2C%20password))%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%3CSPAN%20class%3D%22hljs-built_in%22%3Estring%3C%2FSPAN%3E%20folderUrl%20%3D%20%3CSPAN%20class%3D%22hljs-string%22%3E%40%22https%3A%2F%2Fcompany.sharepoint.com.mcas.ms%2Fsites%2FTestCompany%2FShared%20Documents%2FTestFolder%22%3C%2FSPAN%3E%3B%0A%20%20%20%20%20%20%20%20Uri%20folderUri%20%3D%20%3CSPAN%20class%3D%22hljs-keyword%22%3Enew%3C%2FSPAN%3E%20Uri(folderUrl)%3B%0A%20%20%20%20%0A%20%20%20%20%20%20%20%20Folder%20folder%20%3D%20cc.Web.GetFolderByServerRelativeUrl(folderUri.AbsolutePath)%3B%0A%20%20%20%20%20%20%20%20%3CSPAN%20class%3D%22hljs-built_in%22%3Ebool%3C%2FSPAN%3E%20isEdit%20%3D%20%3CSPAN%20class%3D%22hljs-literal%22%3Efalse%3C%2FSPAN%3E%3B%0A%20%20%20%20%20%20%20%20DateTime%20five_days%20%3D%20DateTime.Now.AddDays(%3CSPAN%20class%3D%22hljs-number%22%3E14%3C%2FSPAN%3E)%3B%0A%20%20%20%20%20%20%20%20ClientResult%3CSTRING%3E%20anonExpEditLink%20%3D%20Web.CreateAnonymousLinkWithExpiration(cc%2C%20folderUrl%2C%20isEdit%2C%20five_days.ToString(%3CSPAN%20class%3D%22hljs-string%22%3E%22yyyy-MM-ddThh%3Amm%3AssZ%22%3C%2FSPAN%3E))%3B%0A%20%20%20%20%20%20%20%20%3CSPAN%20class%3D%22hljs-built_in%22%3Estring%3C%2FSPAN%3E%20anonExpEditLink2%20%3D%20cc.Web.CreateAnonymousLinkWithExpirationForDocument(folderUrl%2C%20ExternalSharingDocumentOption.Edit%2C%20five_days)%3B%0A%20%20%20%20%20%20%20%20cc.ExecuteQuery()%3B%0A%20%20%20%20%0A%20%20%20%20%20%20%20%20cc.Load(folder.Files)%3B%0A%20%20%20%20%20%20%20%20cc.ExecuteQuery()%3B%0A%20%20%20%20%20%20%20%20FileCollection%20fileCol%20%3D%20folder.Files%3B%0A%20%20%20%20%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Eforeach%3C%2FSPAN%3E%20(File%20file%20%3CSPAN%20class%3D%22hljs-keyword%22%3Ein%3C%2FSPAN%3E%20fileCol)%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20Console.WriteLine(anonExpEditLink.Value)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20Console.WriteLine(anonExpEditLink2)%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%7D%3C%2FSTRING%3E%3C%2FPRE%3E%3CP%3EAny%20help%20would%20be%20appreciated%2C%20thank%20you.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2199299%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPnP%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
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).

 

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