【发布时间】:2020-03-04 09:50:33
【问题描述】:
在某些情况下,我目前正在构建一个应用程序,该应用程序将允许员工快速轻松地将本地文件上传到 SharePoint,并通过选择一些文件、输入一些客户的电子邮件然后将其返回一个链接来将它们共享给客户。它大部分都在工作,但是我遇到了与特定用户共享的问题。
- 如果我与不属于我的域的用户共享,他们将获得一个“共享链接”。
- 如果我与属于域的用户共享,他们将获得“直接访问权限”,从而使生成的共享链接对他们无法使用
- 如果我与我的域的外部用户共享,他们将获得“直接访问权限”,这也会使共享链接对他们无法使用
如果你不明白我所说的“分享链接”是什么意思,那就是分享点的这一部分:
我不关心匿名链接,因为我在我的应用程序中已经有了一个选项。
我的目标是将用户添加到共享链接中,无论他们是谁,这可以手动完成(我可以手动进入共享点,将用户添加到直接访问和共享链接访问),但我不能通过 CSOM 弄清楚如何做到这一点。
我目前生成分享链接的功能如下:
/// <summary>
/// Creates a share link for specific users
/// </summary>
/// <param name="context"></param>
/// <param name="site">full link to the folder being shared</param>
/// <param name="emails">List of all emails the folder is being shared to</param>
/// <param name="view">Does this user have view permissions? True = view, false = view & edit</param>
/// <returns>The link</returns>
private string GenerateSpecificLink(ClientContext context, string site, List<string> emails, bool view)
{
var link = "Link not generated";
List<string> successfulEmails = new List<string>();
//Create a new link for each user as a link can only be made for one user at a time
foreach (string email in emails)
{
SharingResult result = null;
//if the user has view permissions
if (view)
{
//the sendEmail bool in the ShareDocument() function is set to false as when it is true, it will send an email to the users automatically that will end up in the spam folder most of the time
//by setting this to false, the user can create their own email with the link to send to the shared user, which will be of much higher quality and wont end up in a spam folder
result = context.Web.ShareDocument(site,
email,
ExternalSharingDocumentOption.View,
false,
"Document Shared as test");
}
//if the user has view & edit permissions
else
{
result = context.Web.ShareDocument(site,
email,
ExternalSharingDocumentOption.Edit,
false,
"Document Shared as test");
}
//if we did successfully share the document, get the link
//ShareLinks are in the form "fullURLLink?user", so we can just trim off the "?user" and get a link that works for *all* users that have been specified
if (result != null)
{
if(result.InvitedUsers != null)
{
link = result.InvitedUsers.First().InvitationLink;
int index = link.IndexOf("?");
if (index > 0) link = link.Substring(0, index);
successfulEmails.Add(email);
_logger.LogInformation($"Generated edit link for {site}. The link works for: {string.Join(", ", successfulEmails)}");
_logger.LogInformation($"Share link: {link}");
}
else
{
_logger.LogWarning($"User {email} did not get an invitation link");
}
}
}
if(link == "Link not generated")
{
return site;
}
return link;
}
Web.ShareDocument() 函数来自OfficeDevPnP.Core ExternalSharingExtensions。理想情况下,我想继续使用它,但如果可能的话,我想找到一种方法来强制它将所有用户添加到共享链接,而不是检查他们是否是域的一部分,如果是,让他们直接访问(甚至给他们直接访问和共享链接访问)。
如果有人对如何使这项工作有任何提示,将不胜感激。如果您需要更多信息,请告诉我。
【问题讨论】:
标签: c# sharepoint-online csom asp.net-core-3.1