Ektron CMS400.NET API Documentation
|
Using the content's ID and the ContentType to get the content and return it as ContentData. Only returns content of type CMSContentType.Content and CMSContentType.Assets.
See Also: The Example section.
public ContentData GetContent(Long Id, Ektron.Cms.Content.EkContent.ContentResultType ContentType);
Public Function GetContent(ByVal Id As Long, ByVal ContentType As Ektron.Cms.Content.EkContent.ContentResultType) As ContentData
Parameters |
Description |
Id |
The ID of the content to be returned. |
ContentType |
Whether the content is published or staged. Enter either: Ektron.Cms.Content.EkContent.ContentResultType.Published or Ektron.Cms.Content.EkContent.ContentResultType.Staged |
ContentData
The following example shows how to create a Web page from which a user can view a content block and its title by entering the content ID into a text box. This example uses some standard drag and drop controls and a small section of VB code utilizing the GetContent method. This method uses the InternalAdmin to get the content. In the first section, we will deal with the standard drag and drop controls. In the second, we'll deal with the code behind.
1. Between the form tags, add a Label with the following information. <asp:Label ID="Label1" runat="server" Text="Content ID: "></asp:Label> 2. Add a text box for the user to enter the content ID. <asp:TextBox ID="txtContentId" runat="server" Width="44px"></asp:TextBox> 3. From the Validation control menu, add a RequiredFieldValidator control. This validates that something appears in the Content ID box. <asp:RequiredFieldValidator ID="rfvContentId" runat="server" ControlToValidate="txtContentId" ErrorMessage="Please enter content ID"></asp:RequiredFieldValidator> 4. Add a couple of breaks for spacing purposes. <br /><br /> 5. Add a button to get the content. We will set the button click event in the code behind. <asp:Button ID="btnGetContent" runat="server" Text="Get Content" /> 6. Add a couple of more breaks for spacing purposes. <br /><br /> 7. Add a results label where the content will appear. This also serves as a place to display an error if necessary. <asp:Label ID="lblResult" runat="server" Width="175px"></asp:Label>
Add the following information to the code behind of your aspx.vb page.
Protected Sub btnGetContent_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGetContent.Click
Dim contentApi As New Ektron.Cms.API.Content.Content
If Not IsNumeric(txtContentId.Text) Then lblResult.Text = "Invalid content ID" Exit Sub End If
Dim contentItem As Ektron.Cms.ContentData
Try contentItem = contentApi.GetContent(CInt(txtContentId.Text), Ektron.Cms.Content.EkContent.ContentResultType.Published)
If (contentItem Is Nothing) Then lblResult.Text = "ContentBlock does not exist" Else lblResult.Text = contentItem.Title & "<br/>" & contentItem.Html End If
Catch ex As Exception lblResult.Text = ex.Message End Try End Sub
Copyright (c) 2008. All rights reserved.
|
What do you think about this topic? Send feedback!
|