如何为 Sharepoint Online 2018 中的文档创建匿名 link

How to create a anonymous link for the documents in Sharepoint Online 2018

我正在尝试为 Sharepoint online 2018 中的文档创建匿名 link。

我尝试使用 Microsoft.SharePoint.Client 提供的 CreateAnonymousLink 方法,但它会抛出错误。

ClientResult<string> result = Microsoft.SharePoint.Client.Web.CreateAnonymousLink(clientContext, absoluteurl, false); clientContext.ExecuteQuery();

我的示例测试代码供您参考。

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();
            }