共用方式為


SharePoint 位置記錄的動作

 

發行︰ 2017年1月

適用於: Dynamics 365 (online)、Dynamics 365 (on-premises)、Dynamics CRM 2016、Dynamics CRM Online

使用 Microsoft Dynamics 365 SDK,您可以在 Microsoft SharePoint 位置記錄上執行下列動作。

  • 將網站位置記錄設為預設

  • 關聯文件位置記錄與實體記錄

  • 擷取位置記錄的絕對和網站集合 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 伺服器的其上層位置記錄。 您針對 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 網站集合上已安裝 適用於 SharePoint Server 的 Microsoft Dynamics CRM 清單元件 時,文件位置記錄才可以自動建立。 如需有關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

如前所述,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. 著作權所有,並保留一切權利。 著作權