You are here: Ektron Namespace > .NET Assemblies > Ektron.Cms.API Namespace > Ektron.Cms.API.Content Namespace > Classes > Blog Class > Blog Methods > AddPost
Ektron CMS400.NET API Documentation
ContentsIndexHome
PreviousUpNext
Blog.AddPost Method

Adds a post to a given blog. Accepts a ContentData class as the post content. Return new post ID. 

See Also: The Example section.  

C#
public Long AddPost(Long blogID, ContentData PostContent, String Categories, Boolean Pingback, String Tags, String TrackbackURL);
Visual Basic
Public Function AddPost(ByVal blogID As Long, ByVal PostContent As ContentData, ByVal Categories() As String, ByVal Pingback As Boolean, ByVal Tags As String, ByVal TrackbackURL As String) As Long
Parameters 
Description 
blogID 
Numeric ID of the blog to which the post is added. 
PostContent 
ContentData class representing the HTML, title, etc. 
Categories 
String Array representing the categories to which this post applies. 
Pingback 
Pingback URL(s) in this post?  
Tags 
String list of tags that applies to this post. 
TrackbackURL 
Trackback URL(s) to notify. 

Numeric ID of the post created. (Long)

The following example shows how to create a Web page from which a user can add a blog post. A user enters the blog's ID, post title and content for the post. This example uses some standard drag and drop controls and a small section of VB code utilizing the AddPost method. This method uses the InternalAdmin to add the blog post. 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, create a table with three rows and three columns.
  2. In the first row, first column, add the following label for the blog ID.
       <asp:Label ID="Label6" runat="server" Text="Blog ID:" Width="76px"></asp:Label>
  3. In the first row, second column, add a text box to enter the blog's ID.
       <asp:TextBox ID="txtBlogId" runat="server" Width="55px"></asp:TextBox>
  4. In the first row, third column, add a RequiredFieldValidator control from the Validation control menu. This validates that something appears in the blog ID box.
       <asp:RequiredFieldValidator ID="rfvBlogId" runat="server" ControlToValidate="txtBlogId"
            ErrorMessage="Please enter user name">Please enter blog ID</asp:RequiredFieldValidator>
  5. In the second row, first column, add the following label for the area to post content.
       <asp:Label ID="Label4" runat="server" Text="Post content:" Width="82px"></asp:Label>
  6. In the second row, second column, add text box where the user can enter the blog post's content.
       <asp:TextBox ID="txtPostContent" runat="server" Width="144px"></asp:TextBox>
  7. In the second row, third column, add a RequiredFieldValidator control from the Validation control menu. This validates that something appears in the blog post's content box.
       <asp:RequiredFieldValidator ID="rfvPostContent" runat="server" ControlToValidate="txtPostContent"
            ErrorMessage="Please enter first name">Please enter content to post</asp:RequiredFieldValidator>
  8. In the third row, first column, add the following label for the blog post's title.
       <asp:Label ID="Label7" runat="server" Text="Post Title: " Width="76px"></asp:Label>
  9. In the third row, second column, add text box where the user can enter the blog post's title.
       <asp:TextBox ID="txtPostTitle" runat="server" Width="144px">Post Title</asp:TextBox>
 10. In the third row, third column, add a RequiredFieldValidator control from the Validation control menu. This validates that something appears in the blog post's title box.
       <asp:RequiredFieldValidator ID="rfvPostTitle" runat="server" ControlToValidate="txtPostTitle"
            ErrorMessage="Please enter first name">Please enter title for the content to post</asp:RequiredFieldValidator>
 11. After the table, add a break and then add a button to submit the blog post.
       <br />
       <asp:Button ID="btnAdd" runat="server" Text="Add Post" Width="70px" />
 12. Add a some breaks for spacing purposes.
      <br /><br />
 13. Add a results label that lets a user know that the blog post has been added and the blog post's ID.
      <asp:Label ID="lblResult" runat="server" Width="432px"></asp:Label>

 

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

  1. Add a button click event.

      Protected Sub btnAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAdd.Click

  2. Check to make sure the blog ID is numeric.

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

  3. Create a Try/Catch around the AddPost method. This allows you to catch any exceptions and helps when debugging.
  4. Create objects for the following items.

          Try
             Dim blogApi As New Ektron.Cms.API.Content.Blog
             Dim postContentData As New Ektron.Cms.ContentData
             Dim categories() As String = New String() {}

  5. Populate postContentData with the Title and the Content of the blog post.

             postContentData.Title = txtPostTitle.text
             postContentData.Html = txtPostContent.Text

  6. Create a place holder for blog post's ID using the AddPost method.

             Dim postId As Integer
             postId = blogApi.AddPost(CInt(txtBlogId.Text), postContentData, categories, False, "", "")

  7. Let the user know the post ID and that it has been added.

             lblResult.Text = "A post was made to the blog with post ID " & postId

  8. 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!