DeleteReport.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /**
  2. Licensed Materials - Property of IBM
  3. IBM Cognos Products: DOCS
  4. (C) Copyright IBM Corp. 2005, 2008
  5. US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with
  6. IBM Corp.
  7. */
  8. // *
  9. // * deleteReport.sln
  10. // *
  11. // * Copyright (C) 2008 Cognos ULC, an IBM Company. All rights reserved.
  12. // * Cognos (R) is a trademark of Cognos ULC, (formerly Cognos Incorporated).
  13. // *
  14. // * Description: This code sample demonstrates how to delete reports using the
  15. // * following methods:
  16. // * - query
  17. // * Use this method to request objects from Content Manager.
  18. // * - delete
  19. // * Use this method to delete objects from the content store.
  20. // *
  21. using System;
  22. using System.Windows.Forms;
  23. using System.Web.Services.Protocols;
  24. using SamplesCommon;
  25. using cognosdotnet_10_2;
  26. namespace DeleteReport
  27. {
  28. /// <summary>
  29. /// Summary description for DeleteReport.
  30. /// </summary>
  31. class DeleteReport
  32. {
  33. /// <summary>
  34. /// The main entry point for the application.
  35. /// </summary>
  36. ///
  37. public DeleteReport(){}
  38. static void Main(string[] args)
  39. {
  40. string cBIUrl = "";
  41. contentManagerService1 cmService = null;
  42. SamplesConnect connectDlg = new SamplesConnect();
  43. DeleteReportDlg deleteReportDlgObject = new DeleteReportDlg();
  44. if (args.GetLength(0) == 0 )
  45. {
  46. // GUI mode
  47. connectDlg.ShowDialog();
  48. if (connectDlg.IsConnectedToCBI() == true)
  49. {
  50. cmService = connectDlg.CBICMS;
  51. cBIUrl = connectDlg.CBIURL;
  52. deleteReportDlgObject.setConnection(cmService, cBIUrl);
  53. BaseClassWrapper[] objectList = BaseClassWrapper.buildReportQueryList(cmService);
  54. deleteReportDlgObject.setReportList(objectList);
  55. deleteReportDlgObject.setSelectedReportIndex(0);
  56. deleteReportDlgObject.ShowDialog();
  57. }
  58. }
  59. }
  60. public bool doDeleteReport(contentManagerService1 cBICMS, BaseClassWrapper report, ref string resultMessage)
  61. {
  62. // Set up the delete() method options.
  63. //
  64. // Set the force option to true. When the force option is
  65. // true, a selected object will be deleted if the current user
  66. // has either write or setPolicy permission for the following
  67. // objects in the Content Store:
  68. // - the selected object
  69. // - the parent of the selected object
  70. // - every descendant of the selected object
  71. // sn_dg_prm_smpl_deletereport_start_0
  72. deleteOptions del = new deleteOptions();
  73. del.force = true;
  74. // The recursive option guarantees that every report history
  75. // attached to this report will also be deleted.
  76. del.recursive = true;
  77. // extract the baseClass from the report parameter
  78. baseClass[] bc = new baseClass[1];
  79. bc[0] = report.baseclassobject;
  80. int nbItemsDeleted = cBICMS.delete( bc, del );
  81. if (nbItemsDeleted>0)
  82. {
  83. resultMessage = "...The item \"" + report.searchPath.value + "\" was successfully deleted.";
  84. }
  85. // sn_dg_prm_smpl_deletereport_end_0
  86. else
  87. {
  88. resultMessage = "An error occurred while deleting the item \"" + report.searchPath.value + "\" .";
  89. }
  90. return true;
  91. }
  92. }
  93. }