I am trying to create a anonymous link for the documents in Sharepoint online 2018.
I have tried using the CreateAnonymousLink method provided by Microsoft.SharePoint.Client but it throws error.
ClientResult<string> result = Microsoft.SharePoint.Client.Web.CreateAnonymousLink(clientContext, absoluteurl, false);
clientContext.ExecuteQuery();
My Sample test code for your reference.
using (var context = new ClientContext("https://tenant.sharepoint.com/sites/Developer"))
{
Console.ForegroundColor = ConsoleColor.Green;
string password = "pw";
SecureString sec_pass = new SecureString();
Array.ForEach(password.ToArray(), sec_pass.AppendChar);
sec_pass.MakeReadOnly();
context.Credentials = new SharePointOnlineCredentials("lee@tenant.onmicrosoft.com", sec_pass);
ClientResult<string> a = Web.CreateAnonymousLink((ClientRuntimeContext)context, "https://tenant.sharepoint.com/sites/Developer/Shared%20Documents/Culture%20Training.docx", false);
context.ExecuteQuery();
Console.WriteLine("done");
Console.ReadKey();
}