You are here: Ektron Namespace > .NET Assemblies > Ektron.Cms.API Namespace > Ektron.Cms.API.Content Namespace > Classes > Content Class > Content Methods > GetContent Method > GetContent
Ektron CMS400.NET API Documentation
ContentsIndexHome
PreviousUpNext
Content.GetContent Method (Long, Ektron.Cms.Content.EkContent.ContentResultType)

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.  

C#
public ContentData GetContent(Long Id, Ektron.Cms.Content.EkContent.ContentResultType ContentType);
Visual Basic
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.

  1. Add a button click event.

   Protected Sub btnGetContent_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGetContent.Click

  1. Create an object for the content API.

       Dim contentApi As New Ektron.Cms.API.Content.Content

  1. Check to make sure the content ID is numeric.

           If Not IsNumeric(txtContentId.Text) Then
               lblResult.Text = "Invalid content ID"
               Exit Sub
           End If

  1. Create an object for to hold the content data that is returned.

       Dim contentItem As Ektron.Cms.ContentData

  1. Create a Try/Catch around the GetContent method. This allows you to catch any exceptions and helps when debugging.

       Try
          contentItem = contentApi.GetContent(CInt(txtContentId.Text), Ektron.Cms.Content.EkContent.ContentResultType.Published)

  1. Add an If statement that displays the content or lets the user know if the content ID does not exist.

          If (contentItem Is Nothing) Then
             lblResult.Text = "ContentBlock does not exist"
          Else
             lblResult.Text = contentItem.Title & "<br/>" & contentItem.Html
          End If
 

  1. If there is an error, let the user know what happened.

       Catch ex As Exception
           lblResult.Text = ex.Message
       End Try
 
   End Sub
Created with a commercial version of Doc-O-Matic. In order to make this message disappear you need to register this software. If you have problems registering this software please contact us at [email protected].
Copyright (c) 2008. All rights reserved.
What do you think about this topic? Send feedback!