Udostępnij za pośrednictwem


How to: Use CMIS APIs to extract information from SharePoint repositories?

What’s CMIS Connector for SharePoint 2010?

Content Management Interoperability Services (CMIS) connector for Microsoft SharePoint Server 2010 enables SharePoint users to interact with content that is stored in any repository that has implemented the CMIS standard. The connector also makes SharePoint Server 2010 content available to any application that has implemented the CMIS standard. The CMIS connector is available as part of the SharePoint 2010 Administration Toolkit.

For more details, refer:

Content Management Interoperability Services (CMIS) connector overview (SharePoint Server 2010)

Microsoft SharePoint 2010 Administration Toolkit v2.0

How to use CMIS APIs to extract information from SharePoint repositories?

Once the CMIS connector is installed on the SharePoint Server, it exposes a set of WCF Services to perform read/write and various operations on the repositories (maps to SharePoint list and libraries).

The set of mapping is available at Mapping the CMIS data model to SharePoint concepts.

I used the Discovery Service <https://<Site url>/_vti_bin/CMIS/soap/discoveryService.svc > exposed by the CMIS Connector to read information from the SharePoint list.

The sample code after adding a Service reference in my project to get information from the Repository (translated to SharePoint List & Document Library) is as:

 //The GUID of the SharePoint Library
string RepositoryID = "c4e0c77c-16ad-48d2-8a1e-0747af0d3b08";

string keyword = "CMIS";

string query = "SELECT cmis:objectId, cmis:name FROM  cmis:document where CONTAINS('" + keyword + "') ";
 DiscoveryServicePortClient DiscoveryClient = null;
try
{
// Get a Client from the Binding Type defined in the App.Config for the application

DiscoveryClient = new DiscoveryServicePortClient("BasicHttpBinding_IDiscoveryServicePort");

DiscoveryClient.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;

DiscoveryClient.ClientCredentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;

DiscoveryClient.ClientCredentials.Windows.AllowNtlm = true;

DiscoveryClient.Open();
cmisExtensionType DisCMISExtType = new cmisExtensionType();

cmisObjectListType resultQuery = DiscoveryClient.query(RepositoryID, query, true, true, enumIncludeRelationships.none, "", "255", "0", DisCMISExtType, null);
Console.WriteLine("Query Completed..........");
Stream streamWrite = File.Create(@"C:\Dlls\QueryResponse3.xml");

XmlSerializer soapWrite = new XmlSerializer(typeof(cmisObjectListType));

soapWrite.Serialize(streamWrite, resultQuery);

streamWrite.Close();
Console.WriteLine("File updated..........");
}
catch (Exception ex)
{
Console.WriteLine("Exception Occured.........");

Console.WriteLine(ex.Message);

Console.WriteLine(ex.StackTrace);
}
finally
{
if (DiscoveryClient != null)
{
DiscoveryClient.Close();
}
}

Comments

  • Anonymous
    November 08, 2012
    The comment has been removed