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

The following example shows how to create a Web page from which a user can add content to the CMS. This example uses some standard drag and drop controls and a small section of VB code utilizing the AddContent method. This method uses the InternalAdmin to add 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 Title: "></asp:Label>
  2. Add a text box with the following information.
      <asp:TextBox ID="txtTitle" runat="server"></asp:TextBox>
  3. From the Validation control menu, add a RequiredFieldValidator control. This validates that something appears in the Title Box.
      <asp:RequiredFieldValidator ID="rfvTitle" runat="server" ControlToValidate="txtTitle"
             ErrorMessage="Please enter content title"></asp:RequiredFieldValidator>
  4. Add a couple of breaks for spacing purposes.
      <br /><br />
  5. Add another label for the content text box.
      <asp:Label ID="Label2" runat="server" Text="Content Text: " Width="87px"></asp:Label>
  6. Add the text box where the content is entered. This is a MultiLine text box.
      <asp:TextBox ID="txtContent" runat="server" Height="105px" TextMode="MultiLine" Width="336px"></asp:TextBox>
  7. Add a some more breaks for spacing purposes.
      <br /><br />
  8. Add a label for to show where to enter the Folder ID.
      <asp:Label ID="Label3" runat="server" Text="Folder Id: " Width="65px"></asp:Label>
  9. Add one last text box for the user to enter the Folder ID where the content will be stored. 
     By default the text box is set to 0 (zero) which is the root folder.
      <asp:TextBox ID="txtFolderId" runat="server" Width="44px">0</asp:TextBox>
 10. Add another RequiredFieldValidator control. This validates that information is entered into the text box.
     Note: This does not validate that the folder actually exists in the CMS.
      <asp:RequiredFieldValidator ID="rfvFolderId" runat="server" ControlToValidate="txtFolderId"
            ErrorMessage="Please enter the Folder Id"></asp:RequiredFieldValidator>
 11. Add a break.
      <br />
 12. Add a label to describe the type of information that needs to be add to the folder ID box.
      <asp:Label ID="Label4" runat="server" Font-Italic="True" Text="Enter a valid Folder ID from the workarea, 0 points to the root folder."
            Width="483px"></asp:Label>
 13. Add two more breaks.
      <br /><br />
 14. Add a button. We will set the button click event in the code behind.
      <asp:Button ID="btnAdd" runat="server" Text="Add" />
 15. Add two last breaks.
      <br /><br />
 16. Add a results label that lets a user know if the add succeeded.
      <asp:Label ID="lblResult" runat="server"></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

  1. Create an object for the content API.

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

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

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

  1. Create an starting content ID of 0 (zero). When the content is added, it will be assigned an ID.

       Dim ID As Integer = 0

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

            Try
               ID = contentApi.AddContent(txtTitle.Text, "Content added by Example.aspx", txtContent.Text, "", _
"", "1033", CInt(txtFolderId.Text), "", "", Nothing)

  1. Add an If statement that lets the user know whether the content was added and the ID of the content.

               If (ID <> 0) Then
                   lblResult.Text = "The above content was added into CMS400.NET with ContentID = " & ID
               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     

  1. Add a page load event so that lblResult.Text is blank when the page first loads.

   Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
      lblResult.Text = ""
   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.