7 - Retrieving documents from Kentico CMS

I'm sure that most of you are interested in the way of retrieving documents from Kentico CMS database in your Silverlight applications. Why didn't I show you that in the example?  The answer is bellow...

I wanted to show you all the ways of retrieving data using one kind of data to enable you to compare the communication methods and their implementations. If I chose documents data I wouldn't be able to do so. I wouldn't be able to get the documents from Kentico CMS database using ADO.NET Data Services easily since the way of retrieving documents is quite complex process to build it on the client. 

So, I recommend you to use any service except ADO.NET Data Services to get documents from Kentico CMS database for now (In Summary chapter I'll mention one more possibility I'm currently working on and which will be really comfortable for you in the future).

What could such service look like?
It can be ASMX, WCF or some kind of HTTP-based service as you could see in previous examples.
Since these services are retrieving users' data using the same method, you can easily modify it to get the documents' data. It means you can modify ServiceHelper.GetUsers(string searchExpression) method to return documents instead of users. Then change list box bindings in Page.xaml from FullName and Email to some document columns (depending on the documents data you are retrieving) and it will work like a charm. I know, it's not clear solution to return documents using method whose name is GetUSERS, so let's create completely new web method instead:

1) First, modify user interface to enable searching for the documents (see source code for more details):

Modify user interface

2) Add a new helper method string GetDocuments(string searchExpression) into ServiceHelper class which will return specified documents:

Helper method

3) Update CMSWebService.cs file to offer web method which will search for the specified documents - we will use our method from ServiceHelper class. In the similar way you can update other services as well:

4) Ensure web service is working by typing path to the CMSWebService.asmx to your web browser. Then select GetDocuments method and enter some search expression:

Ensure web service is working

5) See the results:

Ensure web service is working

6) We have updated web service code but to be able to use GetDocuments method in our demo application we need to update web service reference as well. To do so, please right click on the web service reference and choose Update Service Reference option:

Update web service reference

7) Now you can modify your client application to call the GetDocuments web method to search for the specified documents after the Search button is clicked, as you can see implementation is again very easy:

Search for the documents

Last step is to handle the situation when the requested documents are retrieved, it means to display them:

Display documents

In the very same way you can update implementation of the WCF or HTTP-Based services  which are used in the demo application to enable retrieving documents. 

Example on the E-commerce starter site
Similar example of retrieving documents is built-in directly into the E-commerce starter site - see my latest post for more details. Its source code is located in <Kentico CMS installation folder>/CodeSamples/Silverlight. You can access it also from Start menu -> Programs -> Kentico CMS 4.0 -> Code Samples:

Silverlight code sample


This article is part of the Data communication in Silverlight 2.0 tutorial.
Share this article on   LinkedIn

Petr Vozak

Technology Partnership Product Owner at Kentico. He works with technology partners to enrich the Kentico product offering and bring greater value to those using our products.