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

Delete the content by the content's ID. 

See Also: The Example section.  

C#
public Boolean DeleteContentItem(Long Id);
Visual Basic
Public Function DeleteContentItem(ByVal Id As Long) As Boolean
Parameters 
Description 
Id 
The content's ID. 

Boolean - returns false if the delete succeeds.

The following example shows how to create a Web page from which a user can delete content by entering its ID into a text box. This example uses some standard drag and drop controls and a small section of VB code utilizing the DeleteContentItem method. This method uses the InternalAdmin to delete 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 delete the content. We will set the button click event in the code behind.
      <asp:Button ID="btnDelete" runat="server" Text="Delete" />
 6. Add a couple of more breaks for spacing purposes.
      <br /><br />
 7. 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 btnDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDelete.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 item deleted and set it to true. Note that DeleteContentItem returns false if the delete succeeds.

       Dim deleted As Boolean = True

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

       Try
          deleted = contentApi.DeleteContentItem(CInt(txtContentId.Text))

  1. Add an If statement that lets the user know whether the content was deleted.

          If Not deleted Then
              lblResult.Text = "The above content was deleted from CMS400.Net"
          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!