Export (0) Print
Expand All

Actions on SharePoint location records

Applies To: Microsoft Dynamics CRM 2013, Microsoft Dynamics CRM Online

Using the Microsoft Dynamics CRM SDK, you can perform the following actions on SharePoint location records.

Create, Retrieve, Update, and Delete location records

Using the Microsoft Dynamics CRM SDK messages on the SharePointSite and SharePointDocumentLocation entities, you can create, retrieve, update, and delete records. To perform these operations on the SharePointSite entity, you must have the System Administrator role in Microsoft Dynamics CRM. For a list of supported messages, see SharePointSite entity messages and methods and SharePointDocumentLocation entity messages and methods.

noteNote
Performing these operations on SharePoint location records only manipulates the data in Microsoft Dynamics CRM. It does not create, update, or delete the locations on the SharePoint server.

The SharepointSite.ValidationStatus attribute shows the validation status of the SharePoint site URL. The possible values for this attribute are defined in the Validation Status option set.

The SharepointSite.ValidationStatusErrorCode attribute shows the reason for the validation status of the SharePoint site URL. The possible values for this attribute are defined in the Validation Status Reason option set.

The storage locations on SharePoint Server are hierarchical where the SharePoint site collection is the container that can contain multiple sites, and each site can contain multiple sites or document libraries. Each document library can contain multiple document folders. While creating location records in Microsoft Dynamics CRM, specify the path or the URL of these locations on SharePoint Server.

This is the complete URL of a storage location on SharePoint. You can specify the absolute URL using the SharePointSite.AbsoluteURL or SharePointDocumentLocation.AbsoluteURL property.


// 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);

Similarly, to create a SharePoint document location record by specifying the absolute URL:

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

Absolute URLs are typically provided for the SharePoint site records because these are the container or parent objects under which you want to create other locations for storing and managing your documents.

This is the relative location of a location record with respect to its parent location record on the SharePoint server. When you specify a relative URL for a SharePoint location record, you must also specify the parent object under which it should be created. Microsoft Dynamics CRM internally uses the URL of the parent object to determine the absolute URL for the child object. For example, to create a record for a SharePoint document location under the SharePoint site created in the previous example, you must specify the following:


// 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);

The absolute URL of the child object (document location in this example) is: “Parent_URL/Relative_URL”. So, in this example, the absolute URL of the document location is http://www.example.com/spdocloc.

Relative URLs are typically provided when you want to create a location record lower down the hierarchy or as a child record.

The benefit of using the relative URL is that if you decide to move to a different SharePoint server to store your documents, you just need to update the absolute URL of the parent object location record (probably a site collection or site record) in Microsoft Dynamics CRM, and all the other records down the hierarchy will continue functioning as before because the absolute URLs (determined automatically by Microsoft Dynamics CRM) will not be broken. If you had used absolute URLs for these child location records, you would have to fix the URLs individually.

Set a site location record as default

You can set a SharePoint site location record as default so that all the document locations created using Microsoft Dynamics CRM will be automatically created under this site. To create a site location record as default, use the SharePointSite.IsDefault property, and set it to true. You can set a site location record as default while creating or updating a site location record.

noteNote
Automatic creation of document location records is possible only if the target server is SharePoint Server 2010 and Microsoft Dynamics CRM List Component for Microsoft SharePoint Server 2010 is installed on the target SharePoint Site Collection. For more information, see Microsoft Dynamics CRM List Component for SharePoint Server 2010.

Associate a document location record with an entity record

You can associate a document location record with an entity record. When you do this, all the documents for the entity record are stored at this location on the SharePoint server. You can associate a SharePoint document location record with an entity using the SharePointDocumentLocation.RegardingObjectId property. The following sample shows how you can do this:


// 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);

Retrieve absolute and site collection URLs for a location record

As explained earlier, SharePoint Server follows a hierarchical model to store records. If you want to retrieve the absolute (complete) URL of a location record in the hierarchy and the SiteCollection URL under which the location record is present, you can use the RetrieveAbsoluteAndSiteCollectionUrlRequest message to do so.

The RetrieveAbsoluteAndSiteCollectionUrlRequest message will work properly only if both are true:

  • The Microsoft Dynamics CRM List Component for Microsoft SharePoint Server 2010 is installed on the SharePoint site collection on the target SharePoint server. The component can be installed on a SharePoint Server 2010 site collection only. For more information, see Microsoft Dynamics CRM List Component for SharePoint Server 2010.

  • The location record for the parent SharePoint site collection exists in Microsoft Dynamics CRM, and the SharePointSite.IsGridPresent property was set to true while creating the parent location record.

Otherwise, you will get a blank value or an incorrect value for the SiteCollectionUrl property.

For more information, see RetrieveAbsoluteAndSiteCollectionUrlRequest.

The following sample shows how to use the RetrieveAbsoluteAndSiteCollectionUrl message:


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

See Also

Microsoft Dynamics CRM 2013 and Microsoft Dynamics CRM Online
Send comments about this topic to Microsoft.
© 2014 Microsoft Corporation. All rights reserved.
Show:
© 2014 Microsoft