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.
Protected Sub btnDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDelete.Click
Dim contentApi As New Ektron.Cms.API.Content.Content
If Not IsNumeric(txtContentId.Text) Then lblResult.Text = "Invalid content ID" Exit Sub End If
Dim deleted As Boolean = True
Try deleted = contentApi.DeleteContentItem(CInt(txtContentId.Text))
If Not deleted Then lblResult.Text = "The above content was deleted from CMS400.Net" End If
Catch ex As Exception lblResult.Text = ex.Message End Try End Sub