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.
Protected Sub btnGetBlog_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGetBlog.Click
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
If Not IsNumeric(txtBlogId.Text) Then lblResult.Text = "Invalid Blog ID" Exit Sub End If
If Not IsDate(txtDate.Text) Then lblResult.Text = "Invalid Date" Exit Sub End If
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
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)
If (blogDataItem.Id = 0) Then lblResult.Text = "Error getting blog" Exit Sub End If
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/>"
Catch ex As Exception lblResult.Text = "Error getting blog" End Try