SharePoint 位置记录上的操作

 

发布日期: 2017年1月

适用于: Dynamics 365 (online),Dynamics 365 (on-premises),Dynamics CRM 2016,Dynamics CRM Online

使用 Microsoft Dynamics 365 SDK,您可以对 Microsoft SharePoint 位置记录执行下列操作。

  • 将网站位置记录设置为默认值

  • 将文档位置记录与实体记录相关联

  • 检索位置记录的绝对 URL 和网站集 URL

创建、检索、更新和删除位置记录

SharePointSiteSharePointDocumentLocation 实体使用 Microsoft Dynamics 365 SDK 消息,您可以创建、检索、更新和删除记录。 若要对 SharePointSite 实体执行这些操作,您必须在 Microsoft Dynamics 365 中具有系统管理员角色。 若要获取受支持消息的列表,请参阅 SharePointSite 实体消息和方法SharePointDocumentLocation 实体消息和方法

备注

对 SharePoint 位置记录执行这些操作只会对 Microsoft Dynamics 365 中的数据进行操作。 而不会创建、更新或删除 SharePoint 服务器上的位置。

SharepointSite.ValidationStatus 属性显示 SharePoint 网站 URL 的验证状态。验证状态 (sharepoint_validationstatus) 选项集中定义了此属性的可能值。

SharepointSite.ValidationStatusErrorCode 属性显示 SharePoint 网站 URL 的验证状态。验证状态描述 (sharepoint_validationstatusreason) 选项集中定义了此属性的可能值。

SharePoint Server 上的存储位置是分层次结构的,其中,SharePoint 网站集是一个可包含多个网站的容器,每个网站又可以包含多个网站或文档库。 每个文档库可包含多个文档文件夹。 在 Microsoft Dynamics 365 中创建位置记录时,应指定这些位置在 SharePoint Server 上的路径或 URL。

SharePoint 位置记录的绝对 URL

这是 SharePoint 上存储位置的完整 URL。 可以使用 SharePointSite.AbsoluteURLSharePointDocumentLocation.AbsoluteURL 属性指定绝对 URL。

若要通过指定绝对 URL 来创建 SharePointSite 记录:


// Instantiate a SharePoint site object.
// See the Entity Metadata topic in the SDK documentation to determine 
// which attributes must be set for each entity.
SharePointSite spSite = new SharePointSite
{
    Name = "Sample SharePoint Site",
    Description = "Sample SharePoint Site Location record",

    // TODO: Change this URL to a valid SharePoint URL.                        
    AbsoluteURL = "http://www.example.com",
};

// Create a SharePoint site record named Sample SharePoint Site.
_spSiteId = _serviceProxy.Create(spSite);

' Instantiate a SharePoint site object.
' See the Entity Metadata topic in the SDK documentation to determine 
' which attributes must be set for each entity.
Dim spSite As SharePointSite =
 New SharePointSite With {
  .Name = "Sample SharePoint Site",
  .Description = "Sample SharePoint Site Location record",
  .AbsoluteURL = "http://www.example.com"
 }
' TODO: Change this URL to a valid SharePoint URL.                        

' Create a SharePoint site record named Sample SharePoint Site.
_spSiteId = _serviceProxy.Create(spSite)

同样,若要通过指定绝对 URL 来创建 SharePoint 文档位置记录:

SharePointDocumentLocation spDocLoc = new SharePointDocumentLocation
{
    Name = "Sample SharePoint Document Location",
    Description = "Sample SharePoint Document Location record",
    AbsoluteUrl = "http://www.example.com/spdocloc"   
};
_spDocLocId = _serviceProxy.Create(spDocLoc);

通常为 SharePoint 网站记录提供绝对 URL,因为这是要在其下创建用于存储和管理文档的其他位置的容器或父对象。

备注

SharePointDocumentLocation.LocationType 属性确定 SharePointDocumentLocation 记录指向 SharePoint 文件夹 (0) 还是 OneNote 文件夹 (1)。 在创建 SharePointDocumentLocation 实例(记录)时,SharePointDocumentLocation.LocationType 属性的值将默认设置为 0,指示其指向 SharePoint 文件夹。 有关 OneNote 支持的更多信息,请参阅将 Microsoft Dynamics 365 与 OneNote 集成

SharePoint 位置记录的相对 URL

这是 SharePoint Server 上的某个位置记录相对其父位置记录的相对位置。 在为 SharePoint 位置记录指定相对 URL 时,还必须指定应在其下创建它的父对象。Microsoft Dynamics 365 在内部使用父对象的 URL 来确定子对象的绝对 URL。 例如,若要在前一示例中创建的 SharePoint 网站下为 SharePoint 文档位置创建一个记录,您必须指定以下内容:


// Instantiate a SharePoint document location object.
// See the Entity Metadata topic in the SDK documentation to determine 
// which attributes must be set for each entity.
SharePointDocumentLocation spDocLoc = new SharePointDocumentLocation
{
    Name = "Sample SharePoint Document Location",
    Description = "Sample SharePoint Document Location record",

    // Set the Sample SharePoint Site created earlier as the parent site.
    ParentSiteOrLocation = new EntityReference(SharePointSite.EntityLogicalName, _spSiteId),
    RelativeUrl = "spdocloc",

    // Associate this document location instance with the Fourth Coffee
    // sample account record.
    RegardingObjectId = new EntityReference(Account.EntityLogicalName, _account1Id)
};

// Create a SharePoint document location record named Sample SharePoint Document Location.
_spDocLocId = _serviceProxy.Create(spDocLoc);

' Instantiate a SharePoint document location object.
' See the Entity Metadata topic in the SDK documentation to determine 
' which attributes must be set for each entity.
Dim spDocLoc As SharePointDocumentLocation =
 New SharePointDocumentLocation With {
  .Name = "Sample SharePoint Document Location",
  .Description = "Sample SharePoint Document Location record",
  .ParentSiteOrLocation = New EntityReference(SharePointSite.EntityLogicalName, _spSiteId),
  .RelativeUrl = "spdocloc",
  .RegardingObjectId = New EntityReference(Account.EntityLogicalName, _account1Id)
 }
' Set the Sample SharePoint Site created earlier as the parent site.
' Associate this document location instance with the Fourth Coffee
' sample account record.

' Create a SharePoint document location record named Sample SharePoint Document Location.
_spDocLocId = _serviceProxy.Create(spDocLoc)

子对象的绝对 URL(此示例中的文档位置)为:“Parent_URL/Relative_URL”。 因此,在此示例中,该文档位置的绝对 URL 为 http://www.example.com/spdocloc。

当要在层次结构中的较低级别创建位置记录或作为子记录创建位置记录时,通常提供相对 URL。

使用相对 URL 的好处是:如果您决定转到其他 SharePoint 服务器来存储文档,只需更新 Microsoft Dynamics 365 中父对象位置记录(可能是网站集或网站记录)的绝对 URL,层次结构中的所有其他记录将继续像以前一样工作,因为绝对 URL(由 Microsoft Dynamics 365 自动确定)将不会断开。 如果您已对这些子位置记录使用了绝对 URL,则必须分别修复这些 URL。

将网站位置记录设置为默认值

可以将 SharePoint 网站位置记录设置为默认值,以便在此网站下自动创建使用 Microsoft Dynamics 365 创建的所有文档位置。 若要创建网站位置记录作为默认值,请使用 SharePointSite.IsDefault 属性,并将其设置为 true。 可以在创建或更新网站位置记录时将网站位置记录设置为默认值。

备注

仅当目标站点为 SharePoint 2010 或 SharePoint 2013 服务器且 用于 SharePoint Server 的 Microsoft Dynamics CRM 列表组件 被安装在目标 SharePoint 网站集时,才能自动创建文档位置记录。 有关 Microsoft Dynamics CRM 列表组件 的详细信息,请参阅 Microsoft SharePoint Server 的 Microsoft Dynamics CRM list component

将文档位置记录与实体记录相关联

可以将文档位置记录与实体记录相关联。 执行此操作时,该实体记录的所有文档都将存储在 SharePoint 服务器上的这一位置。 可以使用 SharePointDocumentLocation.RegardingObjectId 属性将 SharePoint 文档位置记录与实体相关联。 以下示例演示如何达到此目的:


// Instantiate a SharePoint document location object.
// See the Entity Metadata topic in the SDK documentation to determine 
// which attributes must be set for each entity.
SharePointDocumentLocation spDocLoc = new SharePointDocumentLocation
{
    Name = "Sample SharePoint Document Location",
    Description = "Sample SharePoint Document Location record",

    // Set the Sample SharePoint Site created earlier as the parent site.
    ParentSiteOrLocation = new EntityReference(SharePointSite.EntityLogicalName, _spSiteId),
    RelativeUrl = "spdocloc",

    // Associate this document location instance with the Fourth Coffee
    // sample account record.
    RegardingObjectId = new EntityReference(Account.EntityLogicalName, _account1Id)
};

// Create a SharePoint document location record named Sample SharePoint Document Location.
_spDocLocId = _serviceProxy.Create(spDocLoc);

' Instantiate a SharePoint document location object.
' See the Entity Metadata topic in the SDK documentation to determine 
' which attributes must be set for each entity.
Dim spDocLoc As SharePointDocumentLocation =
 New SharePointDocumentLocation With {
  .Name = "Sample SharePoint Document Location",
  .Description = "Sample SharePoint Document Location record",
  .ParentSiteOrLocation = New EntityReference(SharePointSite.EntityLogicalName, _spSiteId),
  .RelativeUrl = "spdocloc",
  .RegardingObjectId = New EntityReference(Account.EntityLogicalName, _account1Id)
 }
' Set the Sample SharePoint Site created earlier as the parent site.
' Associate this document location instance with the Fourth Coffee
' sample account record.

' Create a SharePoint document location record named Sample SharePoint Document Location.
_spDocLocId = _serviceProxy.Create(spDocLoc)

检索位置记录的绝对 URL 和网站集 URL

如上所述,SharePoint Server 使用分层模型存储记录。 如果要检索层次结构中某位置记录的绝对(完整)URL 以及其下存在该位置记录的 SiteCollection URL,可以使用 RetrieveAbsoluteAndSiteCollectionUrlRequest 消息来执行此操作。

仅当同时满足以下两个条件时,RetrieveAbsoluteAndSiteCollectionUrlRequest 消息才能正常工作:

  • 用于 SharePoint Server 的 Microsoft Dynamics CRM 列表组件 被安装在目标 SharePoint 2010 或 SharePoint 2013 服务器上的 SharePoint 网站集。 有关详细信息,请参阅Microsoft SharePoint Server 的 Microsoft Dynamics CRM list component

  • 父 SharePoint 网站集的位置记录存在于 Microsoft Dynamics 365 中,并且在创建父位置记录时,SharePointSite.IsGridPresent 属性已设置为 true

否则,您将获得 SiteCollectionUrl 属性的空值或错误值。

有关详细信息,请参阅RetrieveAbsoluteAndSiteCollectionUrlRequest

以下示例演示如何使用 RetrieveAbsoluteAndSiteCollectionUrl 消息。


// Retrieve the absolute URL and the Site Collection URL
// of the SharePoint document location record.
RetrieveAbsoluteAndSiteCollectionUrlRequest retrieveRequest = new RetrieveAbsoluteAndSiteCollectionUrlRequest
{
    Target = new EntityReference(SharePointDocumentLocation.EntityLogicalName, _spDocLocId)
};
RetrieveAbsoluteAndSiteCollectionUrlResponse retriveResponse = (RetrieveAbsoluteAndSiteCollectionUrlResponse)_serviceProxy.Execute(retrieveRequest);

Console.WriteLine("Absolute URL of document location record is '{0}'.", retriveResponse.AbsoluteUrl.ToString());
Console.WriteLine("Site Collection URL of document location record is '{0}'.", retriveResponse.SiteCollectionUrl.ToString());

' Retrieve the absolute URL and the Site Collection URL
' of the SharePoint document location record.
Dim retrieveRequest As RetrieveAbsoluteAndSiteCollectionUrlRequest =
 New RetrieveAbsoluteAndSiteCollectionUrlRequest With {
  .Target = New EntityReference(SharePointDocumentLocation.EntityLogicalName, _spDocLocId)
 }
Dim retriveResponse As RetrieveAbsoluteAndSiteCollectionUrlResponse =
 CType(_serviceProxy.Execute(retrieveRequest), RetrieveAbsoluteAndSiteCollectionUrlResponse)

Console.WriteLine("Absolute URL of document location record is '{0}'.", retriveResponse.AbsoluteUrl.ToString())
Console.WriteLine("Site Collection URL of document location record is '{0}'.", retriveResponse.SiteCollectionUrl.ToString())

另请参阅

RetrieveAbsoluteAndSiteCollectionUrlRequest
RetrieveAbsoluteAndSiteCollectionUrlResponse
将 Microsoft Dynamics 365 与 SharePoint 集成
SharePoint 集成入门
对实体启用文档管理
SharePoint 集成实体
示例:为实体启用文档管理。
示例:创建、检索、更新和删除 SharePoint 位置记录
示例:检索位置记录的绝对 URL 和网站集 URL
将 Microsoft Dynamics 365 与 OneNote 集成

Microsoft Dynamics 365

© 2017 Microsoft。 保留所有权利。 版权