通过在 Exchange 中使用 EWS 为其他用户设置文件夹权限

了解如何使用 Exchange 中的 EWS 托管 API 或 EWS 对文件夹设置权限级别。

文件夹级权限使用户能够访问另一个用户邮箱中的一个或多个文件夹。 文件夹权限类似于委托访问权限,但它们在以下方面有所不同:

  • 文件夹权限不允许用户“代表发送”或“以其他用户身份发送”。 它们仅允许访问文件夹。 用户可以在这些文件夹中创建项目,但无法发送它们。

  • 可以对邮箱中的任何文件夹设置文件夹权限,但只能向“日历”、“联系人”、“收件箱”、“日记”、“便笺”和“任务”文件夹添加代理人。

  • 可以对 特定文件夹设置多个权限。 添加委托时,只能分配 五个权限级别之一。

  • 可以为匿名用户和默认用户设置文件夹权限。 只能向已启用邮件的帐户授予代理访问权限。

如果你熟悉访问控制项 (ACE) 和任意访问控制列表 (DACL) ,你知道用户只能对每个文件夹拥有一组权限。 如果尝试为用户添加一组权限,而他们已有一组权限,则会收到错误。 添加、删除或更新文件夹的权限时,会获取当前 DACL、添加或删除任何 ACE,然后发送更新的 DACL。 不能为同一用户添加多个 ACE。 使用 EWS 托管 API 更新权限时,需要删除用户的当前 ACE,然后将其新 ACE 添加到集合。 如果使用 EWS,只需将以前的 ACE 集替换为新的 ACE 集。

如果要对单个文件夹进行多个权限更改,则可以批量添加、删除或更新 ,只需注意,不能对多个文件夹进行批量用户更新。 需要一次调用才能获取对单个文件夹的权限,需要第二次调用才能更新对该文件夹的权限。 添加、删除或更新用户权限时,对每个任务使用相同的两个方法调用或操作。

表 1. 用于设置文件夹权限的 EWS 托管 API 方法和 EWS 操作

如果想要... 使用此 EWS 托管 API 方法… 使用此 EWS 操作…
启用、删除或更新文件夹权限
Folder.Bind 后跟 Folder.Update
GetFolder 后跟 UpdateFolder
创建文件夹并定义文件夹权限
Folder.Save
CreateFolder

文件夹权限

在设置特定文件夹的文件夹权限时,有相当多的选项。 可以为每个用户设置文件夹的权限级别,这将向 DACL 添加一组预定义的个人权限,也可以对文件夹设置单个权限,但不能混合和匹配。

以下各个权限可用:

  • 可以创建
  • 可以创建子文件夹
  • 是文件夹所有者
  • 文件夹是否可见
  • 是文件夹联系人
  • 编辑项目
  • 删除项目
  • 读取项目

此外,以下权限级别可用于定义单个权限和值的子集,如表 2 所示:

  • 所有者
  • 发行编辑
  • 编辑
  • 发行作者
  • 作者
  • NoneditingAuthor
  • Reviewer
  • 参与者
  • 自定义 - 应用程序无法设置此值。 如果应用程序包含单个权限的自定义集合,则服务器将设置此值。
  • FreeBusyTimeOnly - 只能在“日历”文件夹上设置。
  • FreeBusyTimeAndSubjectAndLocation - 只能在日历文件夹上设置。

下表显示默认基于权限级别应用了哪些单独权限。

表 2. 按权限级别排序的单个权限

权限级别 可以创建项 可以创建子文件夹 是文件夹所有者 文件夹是否可见 是文件夹联系人 编辑项目 删除项目 可以读取项目

False
False
False
False
False



所有者
True
True
True
True
True
全部
全部
FullDetails
发行编辑
True
True
False
True
False
全部
全部
FullDetails
编辑
True
False
False
True
False
全部
全部
FullDetails
发行作者
True
True
False
True
False
拥有
拥有
FullDetails
作者
True
False
False
True
False
拥有
拥有
FullDetails
NoneditingAuthor
True
False
False
True
False

拥有
FullDetails
Reviewer
False
False
False
True
False


FullDetails
参与者
True
False
False
True
False



如果在文件夹级权限请求中指定非自定义权限级别,则无需指定单个权限设置。 如果在设置权限级别时指定了单个权限,响应中将返回 ErrorInvalidPermissionSettings 错误。

使用 EWS 托管 API 添加文件夹权限

以下代码示例演示如何使用 EWS 托管 API 执行以下操作:

  • 为新用户创建新的 FolderPermission 对象。

  • 使用 Bind 方法获取文件夹的当前权限。

  • 将新的 FolderPermissions 添加到 Folder.Permissions 属性。

  • 调用 Update 方法以将新权限保存到服务器。

此示例假定 服务 是邮箱所有者的有效 ExchangeService 对象,并且用户已对 Exchange 服务器进行身份验证。

static void EnableFolderPermissions(ExchangeService service)
{
    // Create a property set to use for folder binding.
    PropertySet propSet = new PropertySet(BasePropertySet.IdOnly, FolderSchema.Permissions);
    // Specify the SMTP address of the new user and the folder permissions level.
    FolderPermission fldperm = new FolderPermission("sadie@contoso.com", FolderPermissionLevel.Editor);
    
    // Bind to the folder and get the current permissions. 
    // This call results in a GetFolder call to EWS.
    Folder sentItemsFolder = Folder.Bind(service, WellKnownFolderName.SentItems, propSet);
 
    // Add the permissions for the new user to the Sent Items DACL.
    sentItemsFolder.Permissions.Add(fldperm);
    // This call results in a UpdateFolder call to EWS.
    sentItemsFolder.Update();
}

以下代码行指定权限级别。

    FolderPermission fldperm = new FolderPermission("sadie@contoso.com", FolderPermissionLevel.Editor);

如果要使用自定义权限级别,请改用此代码。

FolderPermission fldperm = new FolderPermission();
fldperm.UserId = "sadie@Contoso1000.onmicrosoft.com";
fldperm.CanCreateItems = true;
fldperm.CanCreateSubFolders = true;
…

创建具有自定义权限级别的 FolderPermission 对象时,可以设置任何或所有可写 FolderPermission 属性。 但请注意, FolderPermissionLevel 永远不会被应用程序显式设置为 “自定义 ”。 只有在创建 FolderPermission 对象并设置单个权限时 ,FolderPermissionLevel 才会设置为 Custom。

使用 EWS 添加文件夹权限

以下 EWS 代码示例演示如何通过检索当前权限,然后提交新权限列表,向特定文件夹添加权限。

第一步是发送 GetFolder 请求,其中 DistinguishedFolderId 值指定要添加权限的文件夹 (此示例中的“已发送邮件”文件夹) FieldURI 值包括 folder:PermissionSet。 此请求将检索指定文件夹的权限设置。

这也是 EWS 托管 API 在调用 Bind 方法以 添加文件夹权限时发送的 XML 请求。

  <?xml version="1.0" encoding="utf-8"?>
  <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                 xmlns:m="https://schemas.microsoft.com/exchange/services/2006/messages" 
                 xmlns:t="https://schemas.microsoft.com/exchange/services/2006/types" 
                 xmlns:soap="https://schemas.xmlsoap.org/soap/envelope/">
    <soap:Header>
      <t:RequestServerVersion Version="Exchange2007_SP1" />
    </soap:Header>
    <soap:Body>
      <m:GetFolder>
        <m:FolderShape>
          <t:BaseShape>IdOnly</t:BaseShape>
          <t:AdditionalProperties>
            <t:FieldURI FieldURI="folder:PermissionSet" />
          </t:AdditionalProperties>
        </m:FolderShape>
        <m:FolderIds>
          <t:DistinguishedFolderId Id="sentitems" />
        </m:FolderIds>
      </m:GetFolder>
    </soap:Body>
  </soap:Envelope>

服务器使用 GetFolderResponse 消息响应 GetFolder 请求,该邮件包含 NoError的 ResponseCode 元素值,指示已成功检索文件夹。 为提高可读性, 已缩短 FolderIdParentFolderId 值。

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="https://schemas.xmlsoap.org/soap/envelope/">
  <s:Header>
    <h:ServerVersionInfo MajorVersion="15"
                         MinorVersion="0"
                         MajorBuildNumber="893"
                         MinorBuildNumber="17"
                         Version="V2_10"
                         xmlns:h="https://schemas.microsoft.com/exchange/services/2006/types"
                         xmlns="https://schemas.microsoft.com/exchange/services/2006/types"
                         xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
  </s:Header>
  <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <m:GetFolderResponse xmlns:m="https://schemas.microsoft.com/exchange/services/2006/messages"
                         xmlns:t="https://schemas.microsoft.com/exchange/services/2006/types">
      <m:ResponseMessages>
        <m:GetFolderResponseMessage ResponseClass="Success">
          <m:ResponseCode>NoError</m:ResponseCode>
          <m:Folders>
            <t:Folder>
              <t:FolderId Id="CgAAAA=="
                          ChangeKey="AQAAABYAAADOilbYa8KaT7ZgMoTz2P+hAAABiRd1" />
              <t:PermissionSet>
                <t:Permissions>
                  <t:Permission>
                    <t:UserId>
                      <t:DistinguishedUser>Default</t:DistinguishedUser>
                    </t:UserId>
                    <t:CanCreateItems>false</t:CanCreateItems>
                    <t:CanCreateSubFolders>false</t:CanCreateSubFolders>
                    <t:IsFolderOwner>false</t:IsFolderOwner>
                    <t:IsFolderVisible>false</t:IsFolderVisible>
                    <t:IsFolderContact>false</t:IsFolderContact>
                    <t:EditItems>None</t:EditItems>
                    <t:DeleteItems>None</t:DeleteItems>
                    <t:ReadItems>None</t:ReadItems>
                    <t:PermissionLevel>None</t:PermissionLevel>
                  </t:Permission>
                  <t:Permission>
                    <t:UserId>
                      <t:DistinguishedUser>Anonymous</t:DistinguishedUser>
                    </t:UserId>
                    <t:CanCreateItems>false</t:CanCreateItems>
                    <t:CanCreateSubFolders>false</t:CanCreateSubFolders>
                    <t:IsFolderOwner>false</t:IsFolderOwner>
                    <t:IsFolderVisible>false</t:IsFolderVisible>
                    <t:IsFolderContact>false</t:IsFolderContact>
                    <t:EditItems>None</t:EditItems>
                    <t:DeleteItems>None</t:DeleteItems>
                    <t:ReadItems>None</t:ReadItems>
                    <t:PermissionLevel>None</t:PermissionLevel>
                  </t:Permission>
                </t:Permissions>
              </t:PermissionSet>
            </t:Folder>
          </m:Folders>
        </m:GetFolderResponseMessage>
      </m:ResponseMessages>
    </m:GetFolderResponse>
  </s:Body>
</s:Envelope>

接下来,使用 UpdateFolder 操作发送更新的 PermissionSet,其中包括新用户 的权限 。 请注意,在 UpdateFolder 操作中包含相应文件夹的 SetFolderField 元素将覆盖该文件夹上的所有权限设置。 同样,包括 UpdateFolder 操作的 DeleteFolderField 选项也会删除文件夹上的所有权限设置。

这也是 EWS 托管 API 在调用 Update 方法以 添加文件夹权限时发送的 XML 请求。

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xmlns:m="https://schemas.microsoft.com/exchange/services/2006/messages"
               xmlns:t="https://schemas.microsoft.com/exchange/services/2006/types"
               xmlns:soap="https://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <t:RequestServerVersion Version="Exchange2007_SP1" />
  </soap:Header>
  <soap:Body>
    <m:UpdateFolder>
      <m:FolderChanges>
        <t:FolderChange>
          <t:FolderId Id="CgAAAA=="
                      ChangeKey="AQAAABYAAADOilbYa8KaT7ZgMoTz2P+hAAABiRd1" />
          <t:Updates>
            <t:SetFolderField>
              <t:FieldURI FieldURI="folder:PermissionSet" />
              <t:Folder>
                <t:PermissionSet>
                  <t:Permissions>
                    <t:Permission>
                      <t:UserId>
                        <t:DistinguishedUser>Default</t:DistinguishedUser>
                      </t:UserId>
                      <t:PermissionLevel>None</t:PermissionLevel>
                    </t:Permission>
                    <t:Permission>
                      <t:UserId>
                        <t:DistinguishedUser>Anonymous</t:DistinguishedUser>
                      </t:UserId>
                      <t:PermissionLevel>None</t:PermissionLevel>
                    </t:Permission>
                    <t:Permission>
                      <t:UserId>
                        <t:PrimarySmtpAddress>sadie@contoso.com</t:PrimarySmtpAddress>
                      </t:UserId>
                      <t:PermissionLevel>Editor</t:PermissionLevel>
                    </t:Permission>
                  </t:Permissions>
                </t:PermissionSet>
              </t:Folder>
            </t:SetFolderField>
          </t:Updates>
        </t:FolderChange>
      </m:FolderChanges>
    </m:UpdateFolder>
  </soap:Body>
</soap:Envelope>

以下代码行指定权限级别。

<t:Permission>
    <t:UserId>
        <t:PrimarySmtpAddress>sadie@contoso.com</t:PrimarySmtpAddress>
    </t:UserId>
    <t:PermissionLevel>Editor</t:PermissionLevel>
</t:Permission>

如果要使用自定义权限级别,请改用此代码。

<t:Permission>
    <t:UserId>
        <t:PrimarySmtpAddress> sadie@contoso.com </t:PrimarySmtpAddress>
    </t:UserId>
    <t:CanCreateItems>true</t:CanCreateItems>
    <t:CanCreateSubFolders>true</t:CanCreateSubFolders>
    <t:IsFolderOwner>false</t:IsFolderOwner>
    <t:IsFolderVisible>false</t:IsFolderVisible>
    <t:IsFolderContact>false</t:IsFolderContact>
    <t:EditItems>None</t:EditItems>
    <t:DeleteItems>None</t:DeleteItems>
    <t:ReadItems>None</t:ReadItems>
    <t:PermissionLevel>Custom</t:PermissionLevel>
</t:Permission>

服务器使用 UpdateFolderResponse 消息响应 UpdateFolder 请求,该消息包含 NoError的 ResponseCode 元素值,指示文件夹已成功更新。

使用 EWS 托管 API 删除文件夹权限

下面的代码示例演示如何使用 EWS 托管 API 删除对特定文件夹的所有用户权限,默认权限和匿名权限除外,方法是:

  1. 使用 Bind 方法获取文件夹的当前权限。

  2. 循环访问 Permissions 集合并删除单个用户的权限。

  3. 调用 Update 方法以保存更改。

此示例删除对文件夹的所有用户权限。 如果要修改此示例以仅删除特定用户的权限,请更改以下代码行以标识用户的显示名称或 SMTP 地址。

if (sentItemsFolder.Permissions[t].UserId.DisplayName != null || sentItemsFolder.Permissions[t].UserId.PrimarySmtpAddress != null)

此示例假定 服务 是邮箱所有者的有效 ExchangeService 对象,并且用户已对 Exchange 服务器进行身份验证。

static void RemoveFolderPermissions(ExchangeService service)
{
    // Create a property set to use for folder binding.
    PropertySet propSet = new PropertySet(BasePropertySet.FirstClassProperties, FolderSchema.Permissions);
    // Bind to the folder and get the current permissions. 
    // This call results in a GetFolder call to EWS.
    Folder sentItemsFolder = Folder.Bind(service, new FolderId(WellKnownFolderName.SentItems, "primary@contoso.com"), propSet);
    // Iterate through the collection of permissions and remove permissions for any 
    // user with a display name or SMTP address. This leaves the anonymous and 
    // default user permissions unchanged. 
    if (sentItemsFolder.Permissions.Count != 0)
    {
        for (int t = 0; t < sentItemsFolder.Permissions.Count; t++)
        {
            // Find any permissions associated with the specified user and remove them from the DACL
            if (sentItemsFolder.Permissions[t].UserId.DisplayName != null || sentItemsFolder.Permissions[t].UserId.PrimarySmtpAddress != null)
            {
                sentItemsFolder.Permissions.Remove(sentItemsFolder.Permissions[t]);
            }
        }
    }
    // This call results in an UpdateFolder call to EWS.
    sentItemsFolder.Update();
}

使用 EWS 删除文件夹权限

以下 EWS 代码示例演示如何删除特定文件夹的所有用户权限,默认权限和匿名权限除外。

首先,发送 GetFolder 请求,其中 DistinguishedFolderId 值指定删除权限的文件夹 (此示例中的“已发送邮件”文件夹) 且 FieldURI 值包括 folder:PermissionSet。 此请求将检索指定文件夹的 PermissionSet

这也是 EWS 托管 API 在调用 Bind 方法以 删除文件夹权限时发送的 XML 请求。

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xmlns:m="https://schemas.microsoft.com/exchange/services/2006/messages"
               xmlns:t="https://schemas.microsoft.com/exchange/services/2006/types"
               xmlns:soap="https://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <t:RequestServerVersion Version="Exchange2007_SP1" />
  </soap:Header>
  <soap:Body>
    <m:GetFolder>
      <m:FolderShape>
        <t:BaseShape>AllProperties</t:BaseShape>
        <t:AdditionalProperties>
          <t:FieldURI FieldURI="folder:PermissionSet" />
        </t:AdditionalProperties>
      </m:FolderShape>
      <m:FolderIds>
        <t:DistinguishedFolderId Id="drafts">
          <t:Mailbox>
            <t:EmailAddress>primary@contoso.com</t:EmailAddress>
          </t:Mailbox>
        </t:DistinguishedFolderId>
      </m:FolderIds>
    </m:GetFolder>
  </soap:Body>
</soap:Envelope>

服务器使用 GetFolderResponse 消息响应 GetFolder 请求,该邮件包含 NoError的 ResponseCode 元素值,指示已成功检索文件夹。 为了提高可读性, 已缩短 FolderIdParentFolderId 元素的值。

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="https://schemas.xmlsoap.org/soap/envelope/">
  <s:Header>
    <h:ServerVersionInfo MajorVersion="15"
                         MinorVersion="0"
                         MajorBuildNumber="893"
                         MinorBuildNumber="17"
                         Version="V2_10"
                         xmlns:h="https://schemas.microsoft.com/exchange/services/2006/types"
                         xmlns="https://schemas.microsoft.com/exchange/services/2006/types"
                         xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
  </s:Header>
  <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <m:GetFolderResponse xmlns:m="https://schemas.microsoft.com/exchange/services/2006/messages"
                         xmlns:t="https://schemas.microsoft.com/exchange/services/2006/types">
      <m:ResponseMessages>
        <m:GetFolderResponseMessage ResponseClass="Success">
          <m:ResponseCode>NoError</m:ResponseCode>
          <m:Folders>
            <t:Folder>
              <t:FolderId Id="EAAAAA=="
                          ChangeKey="AQAAABYAAADOilbYa8KaT7ZgMoTz2P+hAAABiRd5" />
              <t:ParentFolderId Id="CQAAAA=="
                                ChangeKey="AQAAAA==" />
              <t:FolderClass>IPF.Note</t:FolderClass>
              <t:DisplayName>Drafts</t:DisplayName>
              <t:TotalCount>0</t:TotalCount>
              <t:ChildFolderCount>0</t:ChildFolderCount>
              <t:EffectiveRights>
                <t:CreateAssociated>true</t:CreateAssociated>
                <t:CreateContents>true</t:CreateContents>
                <t:CreateHierarchy>true</t:CreateHierarchy>
                <t:Delete>true</t:Delete>
                <t:Modify>true</t:Modify>
                <t:Read>true</t:Read>
                <t:ViewPrivateItems>true</t:ViewPrivateItems>
              </t:EffectiveRights>
              <t:PermissionSet>
                <t:Permissions>
                  <t:Permission>
                    <t:UserId>
                      <t:DistinguishedUser>Default</t:DistinguishedUser>
                    </t:UserId>
                    <t:CanCreateItems>false</t:CanCreateItems>
                    <t:CanCreateSubFolders>false</t:CanCreateSubFolders>
                    <t:IsFolderOwner>false</t:IsFolderOwner>
                    <t:IsFolderVisible>false</t:IsFolderVisible>
                    <t:IsFolderContact>false</t:IsFolderContact>
                    <t:EditItems>None</t:EditItems>
                    <t:DeleteItems>None</t:DeleteItems>
                    <t:ReadItems>None</t:ReadItems>
                    <t:PermissionLevel>None</t:PermissionLevel>
                  </t:Permission>
                  <t:Permission>
                    <t:UserId>
                      <t:DistinguishedUser>Anonymous</t:DistinguishedUser>
                    </t:UserId>
                    <t:CanCreateItems>false</t:CanCreateItems>
                    <t:CanCreateSubFolders>false</t:CanCreateSubFolders>
                    <t:IsFolderOwner>false</t:IsFolderOwner>
                    <t:IsFolderVisible>false</t:IsFolderVisible>
                    <t:IsFolderContact>false</t:IsFolderContact>
                    <t:EditItems>None</t:EditItems>
                    <t:DeleteItems>None</t:DeleteItems>
                    <t:ReadItems>None</t:ReadItems>
                    <t:PermissionLevel>None</t:PermissionLevel>
                  </t:Permission>
                  <t:Permission>
                    <t:UserId>
                      <t:SID>S-1-5-21-1337771579-694202782-848329751-1535223</t:SID>
                      <t:PrimarySmtpAddress>sadie@Contoso.com</t:PrimarySmtpAddress>
                      <t:DisplayName>Sadie Daniels</t:DisplayName>
                    </t:UserId>
                    <t:CanCreateItems>true</t:CanCreateItems>
                    <t:CanCreateSubFolders>false</t:CanCreateSubFolders>
                    <t:IsFolderOwner>false</t:IsFolderOwner>
                    <t:IsFolderVisible>true</t:IsFolderVisible>
                    <t:IsFolderContact>false</t:IsFolderContact>
                    <t:EditItems>All</t:EditItems>
                    <t:DeleteItems>All</t:DeleteItems>
                    <t:ReadItems>FullDetails</t:ReadItems>
                    <t:PermissionLevel>Editor</t:PermissionLevel>
                  </t:Permission>
                </t:Permissions>
              </t:PermissionSet>
              <t:UnreadCount>0</t:UnreadCount>
            </t:Folder>
          </m:Folders>
        </m:GetFolderResponseMessage>
      </m:ResponseMessages>
    </m:GetFolderResponse>
  </s:Body>
</s:Envelope>

接下来,使用 UpdateFolder 操作发送更新的 PermissionSet,其中不包括已删除用户 的权限

这也是 EWS 托管 API 在调用 Update 方法以 删除文件夹权限时发送的 XML 请求。

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xmlns:m="https://schemas.microsoft.com/exchange/services/2006/messages"
               xmlns:t="https://schemas.microsoft.com/exchange/services/2006/types"
               xmlns:soap="https://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <t:RequestServerVersion Version="Exchange2007_SP1" />
  </soap:Header>
  <soap:Body>
    <m:UpdateFolder>
      <m:FolderChanges>
        <t:FolderChange>
          <t:FolderId Id="EAAAAA=="
                      ChangeKey="AQAAABYAAADOilbYa8KaT7ZgMoTz2P+hAAABiRd5" />
          <t:Updates>
            <t:SetFolderField>
              <t:FieldURI FieldURI="folder:PermissionSet" />
              <t:Folder>
                <t:PermissionSet>
                  <t:Permissions>
                    <t:Permission>
                      <t:UserId>
                        <t:DistinguishedUser>Default</t:DistinguishedUser>
                      </t:UserId>
                      <t:PermissionLevel>None</t:PermissionLevel>
                    </t:Permission>
                    <t:Permission>
                      <t:UserId>
                        <t:DistinguishedUser>Anonymous</t:DistinguishedUser>
                      </t:UserId>
                      <t:PermissionLevel>None</t:PermissionLevel>
                    </t:Permission>
                  </t:Permissions>
                </t:PermissionSet>
              </t:Folder>
            </t:SetFolderField>
          </t:Updates>
        </t:FolderChange>
      </m:FolderChanges>
    </m:UpdateFolder>
  </soap:Body>
</soap:Envelope>

服务器使用 UpdateFolderResponse 消息响应 UpdateFolder 请求,该消息包含 NoErrorResponseCode 元素值,指示更新成功。

使用 EWS 托管 API 更新文件夹权限

还可以使用 EWS 托管 API 更新特定文件夹的文件夹权限。 若要更新权限,请执行以下操作:

  1. 删除过时权限的文件夹权限 ,但不要调用 Update 方法 (尚未) 。

  2. 为新用户或更改的用户添加文件夹权限

  3. 调用 Update 方法以保存更改。

如果尝试为同一用户添加两组权限,将收到 ServiceResponseException 错误,其中包含以下说明:“指定的权限集包含重复的 UserId”。 在这种情况下,请从 Permission 集合中删除当前权限,然后将新权限添加到 Permission 集合。

使用 EWS 更新文件夹权限

还可以通过结合使用删除和添加过程,使用 EWS 更新特定文件夹的文件夹权限。 若要更新权限,请执行以下操作:

  1. 使用 GetFolder 操作检索文件夹的当前权限。

  2. 使用 UpdateFolder 操作发送更新的权限列表。

这与使用 EWS 启用或禁用访问权限的两个操作相同。 唯一的区别在于,收到 GetFolder 响应时,它将包含用户 的权限 集。 只需将现有 Permission 元素替换为新的 Permission 元素,然后使用新的 Permission 值发送 UpdateFolder 操作。

如果尝试为同一用户添加两组权限,将收到 ErrorDuplicateUserIdsSpecifiedResponseCode 值。 在这种情况下,请从请求中删除用户的过时权限值,然后重试请求。

后续步骤

向用户授予对特定文件夹的权限后,用户可以以代理人身份访问该文件夹。 有关更多信息,请参阅:

另请参阅