You are here: Ektron Namespace > .NET Assemblies > Ektron.Cms.API Namespace > Ektron.Cms.API.Content Namespace > Classes > Blog Class > Blog Methods > GetBlog Method > GetBlog
Ektron CMS400.NET API Documentation
ContentsIndexHome
PreviousUpNext
Blog.GetBlog Method (Long, String, Integer, Integer)

Returns a BlogData class for a given blog ID, with parameters. This class contains the content for a blog, the post info, the roll, and the categories information. See the BlogData class for more information.

C#
public BlogData GetBlog(Long ID, String StartDate, int MaxEntries, int LanguageID);
Visual Basic
Public Function GetBlog(ByVal ID As Long, ByVal StartDate As String, ByVal MaxEntries As Integer, ByVal LanguageID As Integer) As BlogData
Parameters 
Description 
ID 
The ID of the blog. This is a numeric value that corresponds to the folder ID of the blog. 
StartDate 
The date to start getting entries. Used if you want to get historical information. Gets information only for the date specified. 
MaxEntries 
The total number of posts to return. This is an integer value.
If set to 0, the postsvisible property of the blog is used.
If set to -1, the content is not returned, only the post info for the content. 
LanguageID 
The language ID for the content to get. An integer value. 

For a given blog ID, this returns either null or a BlogData class with the associated posts. This also includes the roll, categories, and post information.

Developers are advised to check for null prior to using.

The following example shows how to create a Web page from which a user can retrieve blog information by specifying a blog ID, a date and how to handle post information. The sample returns BlogData for the Title, Tagline, Categories, Blog roll links and the number of posts. To create this example, we use some standard drag and drop controls and a small section of VB code utilizing the GetBlog method. This method uses the InternalAdmin to retrieve the blog information. 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. Create a table with three rows and two columns.
  2. In the first row, first column, add a label that shows where to enter the blog's ID.
       <asp:Label ID="Label1" runat="server" Text="Blog ID: "></asp:Label>
  3. In the first row, second column, add a text box for the user to enter the blog ID and a RequiredFieldValidator to validate that something appears in the blog ID box.
       <asp:TextBox ID="txtBlogId" runat="server" Width="63px">41</asp:TextBox>
       <asp:RequiredFieldValidator ID="rfvBlogId" runat="server" ControlToValidate="txtBlogId"
                ErrorMessage="Please enter blog ID"></asp:RequiredFieldValidator>
  4. In the second row, first column, add a label that shows where to enter the date.
       <asp:Label ID="Label2" runat="server" Text="Date: "></asp:Label>
  5. In the second row, second column, add a text box for the user to enter the date and a RequiredFieldValidator to validate that something appears in the date box.
       <asp:TextBox ID="txtDate" runat="server" Width="63px"></asp:TextBox>
       <asp:RequiredFieldValidator ID="rfvDate" runat="server" ControlToValidate="txtDate" 
              ErrorMessage="Please enter the post date"></asp:RequiredFieldValidator>
  6. In the third row, first column, add a label for the posts.
         <asp:Label ID="Label4" runat="server" Text="Posts:"></asp:Label>
  7. In the third row, second column, add the following radio buttons with breaks between each one.
         <asp:RadioButton ID="rb_forday" runat="server" Checked="True" GroupName="rb_num" Text="All posts for that day only" /><br />
         <asp:RadioButton ID="rb_dayprior" runat="server" GroupName="rb_num" Text="All posts for that day and before" /><br />
         <asp:RadioButton ID="rb_month" runat="server" GroupName="rb_num" Text="All posts for the month that day falls on." /><br />
         <asp:RadioButton ID="rb_Custom" runat="server" GroupName="rb_num" Text="Starting from the date, this number of posts:" />
  8. Add a text box at the end of the last radio button so a user can enter the quantity of posts to return.  
         <asp:TextBox ID="txt_num" runat="server" Width="63px">1</asp:TextBox>
  9. After the table, add a break.
         <br />
 10. Add a button to retrieve the blog information.
         <asp:Button ID="btnGetBlog" runat="server" Text="Get Blog" Width="72px" />
 11. Add a couple of breaks for spacing purposes.
         <br /><br />
 12. Add a results label that displays the blog information. It will also display a message if there is an error.
         <asp:Label ID="lblResult" runat="server" Width="604px" Height="113px"></asp:Label>

 

Add the following information to the code behind of your aspx.vb page.

  1. Add a button click event.

       Protected Sub btnGetBlog_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGetBlog.Click  

  1. Create the following objects.

       Dim iPostNum As Integer = -1
       Dim blogDataItem As New Ektron.Cms.BlogData
       Dim blogApi As New Ektron.Cms.API.Content.Blog
       Dim i As Integer

  1. Check to make sure txtBlogId is numeric.

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

  1. Check to make sure txtDate is a date.

       If Not IsDate(txtDate.Text) Then
           lblResult.Text = "Invalid Date"
           Exit Sub
       End If

  1. Create a Try/Catch.
  2. Add a check to see which radio button is active and set the number of posts.

       Try
          If Me.rb_forday.Checked = True Then
              iPostNum = -1
          ElseIf Me.rb_month.Checked = True Then
              iPostNum = -2
          ElseIf Me.rb_dayprior.Checked = True Then
              iPostNum = 0
          ElseIf Me.rb_Custom.Checked = True Then
              If IsNumeric(Me.txt_num.Text) AndAlso CInt(Me.txt_num.Text) > 0 Then
                  iPostNum = Convert.ToInt32(Me.txt_num.Text)
              Else
                  Me.txt_num.Text = "1"
                  iPostNum = 1
              End If
          End If

  1. Get the blog.

          blogDataItem = blogApi.GetBlog(CInt(txtBlogId.Text), txtDate.Text, iPostNum, 1033)

Note: To get the blog using the path instead of the ID use the following code. blogDataItem = blogApi.GetBlog("~SiteRoot~\TestBlog", txtDate.Text, -1, 1033) 

  1. Check to see if the blog exists.
 

          If (blogDataItem.Id = 0) Then
              lblResult.Text = "Error getting blog"
              Exit Sub
          End If

  1. Display the results for the user.

         lblResult.Text = "Title: " & blogDataItem.Title & "<br/>"
         lblResult.Text &= "Tagline: " & blogDataItem.Tagline & "<br/>"
         If blogDataItem.Categories.Length <> 0 Then
             lblResult.Text &= "Categories: "
             For i = 0 To blogDataItem.Categories.Length - 1 Step 1
                 lblResult.Text &= blogDataItem.Categories(i) & " "
             Next
             lblResult.Text &= "<br>"
         End If
 
         If blogDataItem.BlogRoll.Items.Length <> 0 Then
             lblResult.Text &= "Blog roll links: "
             For i = 0 To blogDataItem.BlogRoll.Items.Length - 1 Step 1
                 lblResult.Text &= "<a href=""" & blogDataItem.BlogRoll.Items(i).URL & """ target=""mainFrame"">" & blogDataItem.BlogRoll.Items(i).LinkName & "</a>" & "  "
             Next
             lblResult.Text &= "<br>"
         End If
         lblResult.Text &= "Number of posts: " & blogDataItem.Content.Length & "<br/>"

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

      Catch ex As Exception
              lblResult.Text = "Error getting blog"
      End Try
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!