Querying the images from an album
The Book control queries the images from a specific album. To query the images, you must add references to the following assemblies in the BookWidget project:
-
Telerik.Sitefinity.Model
On Browse tab navigate to folder SDK\Content\Common\Dependencies inside Sitefinity installation folder and find the assembly.
-
Telerik.OpenAccess
On Browse tab navigate to folder SDK\Content\Common\Dependencies inside Sitefinity installation folder and find the assembly.
-
System.Runtime.Serialization
You can find the assembly on .NET tab.
After adding the references import the following using statements in the Book.cs file:
using System.Collections;
using Telerik.Sitefinity;
Specifying the album title
Before querying the images, define a property, which specifies the name of the album, where the images are placed.
Open the Book.cs file and insert the following code:
private string albumTitle;
[Category("Book Properties")]
public string AlbumTitle
{
get
{
return this.albumTitle;
}
set
{
this.albumTitle = value;
}
}
By default Sitefinity creates a field in the property editor of the control for each of your public properties. The user can use the field generated for the AlbumTitle property, to enter a value. If you do not want the system to generate a field for the AlbumTitle property, mark it with a [Browsable(false)] attribute.
NOTE: Sitefinity automatically handles persistence in the background.
TIP: You can categorize the properties added to the property editor of the control. To add a property to a specific category, mark it with the[Category("CategoryName")] attribute.
Getting the domain URL
The URLs of the images are stored in a format relative to the domain of the Sitefinity application. The Silverlight application requires them in absolute form. To provide the absolute path to the image, you must create a method, which concatenates the path of the domain to the relative path of the image. Following is the code for the method, which you must place in the Book.cs file:
private string GetAuthorityUrl()
{
var authority = this.Page.Request.Url.GetLeftPart(UriPartial.Authority);
return VirtualPathUtility.RemoveTrailingSlash(authority);
}
To get the path of the domain, call the GetLeftPart(UriPartial) method of the Uri class with UriPartial.Authority value for the argument.
For more information about the GetLeftPart method, see Uri.GetLeftPart Method.
Querying the images
After defining a property for the title of the album, you must query the images. To do this, you use Sitefinity's Fluent API. It allows you to access and use the data from the Sitefinity modules.
Create a method, which queries the images and returns them as List of Hastable. Following is the code for the method, which you must place in the Book.cs file:
private List<Hashtable> GetImages()
{
List<Hashtable> results = new List<Hashtable>();
string title = this.AlbumTitle;
//get IQueryable of images from the Fluent API.
var images = App.WorkWith().Images()
.Where(
(w) => w.Parent.Title == title &&
w.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live)
.Get();
var authority = this.GetAuthorityUrl();
foreach (Telerik.Sitefinity.Libraries.Model.Image v in images)
{
Hashtable table = new Hashtable();
table.Add("Url", authority + v.MediaUrl);
results.Add(table);
}
return results;
}
For more information about querying images using the Fluent API, see Managing images.