Logo
programming4us
programming4us
programming4us
programming4us
Home
programming4us
XP
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Windows Phone
 
Windows Server

Microsoft Content Management Server : Deleting Objects

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
3/20/2011 5:06:55 PM
The PAPI has a Delete() method for each channel, posting, template, template gallery, resource gallery, and resource object. We have created quite a few test objects in the repository, so let’s write a Delete dialog so that CMS Explorer can remove them:

1.
Add a new web form to the CMSExplorer project and name it Delete.aspx.

2.
In Design view, drag and drop styles.css from Solution Explorer onto the web form.

3.
Toggle to HTML view and add a table with four rows:

<table>
<tr>
<td><h1>Confirm Delete</h1></td>
</tr>
<tr>
<td>
Click YES to permanently delete
(Add literal to show the path of the item to be deleted here)</td>
</tr>
<tr>
<td align="right">
(Add the Yes button here)
<INPUT type="button" value="No" onclick="javascript:window.close();"
style="width:120px">
</td>
</tr>
<tr>
<td>(Add label for displaying error messages here)</td>
</tr>
</table>

4.
Switch to Design view. Add controls (from the Web Forms section of the Toolbox) to the form and arrange them as shown in the diagram below:

ControlPropertyValue
LiteralIDlitCurrentItem
 Text(empty string)
LabelIDlblErrorMessage
 Text(empty string)
ButtonIDbtnYes
 TextYes
 Width120px

5.
Open the code-behind file for the form. As before, in addition to the existing namespaces, import Microsoft.ContentManagement.Publishing:

. . . code continues . . .
// MCMS PAPI using Microsoft.ContentManagement.Publishing;

namespace CmsExplorer
{
. . . code continues . . .
}

6.
In the Page_Load() event handler, we get a reference to the current CmsHttpContext as well as the object to be deleted as specified by the CmsObjectGuidlitCurrentItem literal.

I
In addition, we check to see if the user has the rights to delete the object. We do so by retrieving the value of the HierarchyItem.CanDelete property. The btnYes button is enabled only if the user can delete the object.
CmsHttpContext cmsContext;
HierarchyItem deletedObject;

private void Page_Load(object sender, System.EventArgs e)
{
cmsContext = CmsHttpContext.Current;
lblErrorMessage.Text = String.Empty;
string cmsObjectGuid = String.Empty;
if (Request.QueryString["CMSObjectGuid"] != null)
{
cmsObjectGuid = Request.QueryString["CMSObjectGuid"];
deletedObject = cmsContext.Searches.GetByGuid(cmsObjectGuid);
}
// display the path of the object to be deleted
if (!Page.IsPostBack)
{
litCurrentItem.Text = deletedObject.Path;
}
btnYes.Enabled = deletedObject.CanDelete;
}

7.
Switch back to Design view and double-click on the btnYes button. In the btnYes_Click() event handler, simply make a call to the HierarchyItem.Delete() method and commit the delete:

private void btnYes_Click(object sender, System.EventArgs e)
{
try
{
deletedObject.Delete();
cmsContext.CommitAll();
// display the success message
lblErrorMessage.Text = "Item deleted successfully!";
}
catch(Exception ex)
{
// rollback all changes
cmsContext.RollbackAll();
// the CMS context needs to be disposed of after a rollback
cmsContext.Dispose();
// display error message
lblErrorMessage.Text = ex.Message;
}
}

If any errors occur in the process, the delete operation is rolled back and an error message displayed.

You need to be aware of some key points when deleting objects using the PAPI:

  • A container with objects cannot be deleted until all items within it are deleted as well.

  • Objects with existing dependants cannot be deleted until all dependants are removed. For instance, if there are postings based on a template, the template cannot be deleted until those postings are also deleted.

  • Postings that link to the resource will maintain a link to the resource even though the resource has been deleted. This was designed to prevent broken links. However the file will no longer be accessible by resource managers. Only administrators will be able to view them.

  • Unlike the Delete option in Site Manager, where deleted objects are stored in the Deleted Items bin and can be recovered, objects deleted using the PAPI are no longer accessible once the delete has been committed. The MCMS background process will remove all resources that aren’t referenced by a posting. Resources referenced by a posting can be recovered by requesting a stored procedure from Microsoft Support (reference number: SOX040517700117).

Other -----------------
- Microsoft Content Management Server : Managing Resources (part 2) - Replacing Resources
- Microsoft Content Management Server : Managing Resources (part 1) - Creating Resources
- Routing with Windows Server 2003 : Configuring Packet Filters
- Routing with Windows Server 2003 : Configuring and Managing Routing Protocols (part 2) - OSPF Overview & Understanding DHCP Relay Agent
- Routing with Windows Server 2003 : Configuring and Managing Routing Protocols (part 1) - Configuring RIP
- Routing with Windows Server 2003 : Configuring NAT
- Windows Server 2008 R2 : Choosing Between Traditional VPN Technologies and DirectAccess
- DirectAccess in Windows Server 2008 R2 (part 2)
- DirectAccess in Windows Server 2008 R2 (part 1)
- Understanding Network Services and Active Directory Domain Controller Placement for Exchange Server 2010 : Understanding AD Functionality Modes and Their Relationship to Exchange Server Groups
 
 
Top 10
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
 
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server