PageRenderTime 53ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/Zieglers.CodePlex.BulkListActions/BulkListActions/CustomActionHandlers.cs

#
C# | 180 lines | 92 code | 32 blank | 56 comment | 6 complexity | b50010452902e526a153f042c4161233 MD5 | raw file
  1. // ******************************************************************************
  2. // Developed by Oguz Demirel
  3. // Date: March 17, 2010
  4. // ******************************************************************************
  5. namespace BulkListActions
  6. {
  7. using System;
  8. using System.Net;
  9. using System.Web;
  10. using System.Collections.Specialized;
  11. using Microsoft.SharePoint;
  12. using Microsoft.SharePoint.Utilities;
  13. using System.Collections.Generic;
  14. public class DeleteItemsHandler : CustomHandlerBase
  15. {
  16. // This is where you override abstract class ProcessItem
  17. // Simply code here your custom logic which will be applied
  18. // on the list item
  19. public override void ProcessItem(SPListItem item)
  20. {
  21. // Delete item
  22. item.Delete();
  23. }
  24. } // end - class DeleteItemsHandler
  25. public class CheckOutItemsHandler : CustomHandlerBase
  26. {
  27. // This is where you override abstract class ProcessItem
  28. // Simply code here your custom logic which will be applied
  29. // on the list item
  30. public override void ProcessItem(SPListItem item)
  31. {
  32. // Check Out item
  33. item.File.CheckOut();
  34. }
  35. } // end - class CheckOutItemsHandler
  36. public class CheckInItemsHandler : CustomHandlerBase
  37. {
  38. // This is where you override abstract class ProcessItem
  39. // Simply code here your custom logic which will be applied
  40. // on the list item
  41. public override void ProcessItem(SPListItem item)
  42. {
  43. if (//item.ParentList.ForceCheckout &&
  44. item.File.CheckOutStatus != SPFile.SPCheckOutStatus.None)
  45. // Check In item
  46. item.File.CheckIn("Checked-in by custom actions menu item.");
  47. }
  48. } // end - class CheckInItemsHandler
  49. public class PublishItemsHandler : CustomHandlerBase
  50. {
  51. // This is where you override abstract class ProcessItem
  52. // Simply code here your custom logic which will be applied
  53. // on the list item
  54. public override void ProcessItem(SPListItem item)
  55. {
  56. // Publish item
  57. item.File.Publish("Published by custom actions menu item.");
  58. }
  59. } // end - class PublishItemsHandler
  60. public class UnpublishItemsHandler : CustomHandlerBase
  61. {
  62. // This is where you override abstract class ProcessItem
  63. // Simply code here your custom logic which will be applied
  64. // on the list item
  65. public override void ProcessItem(SPListItem item)
  66. {
  67. // UnPublish item
  68. item.File.UnPublish("Unpublished by custom actions menu item.");
  69. }
  70. } // end - class UnpublishItemsHandler
  71. public class UpdateMetaDataHandler : CustomHandlerBase
  72. {
  73. // Store item IDs to process
  74. string itemGUIDs = "&IDs=";
  75. // Store list ID
  76. string listID = "&ListID=";
  77. // Store referrer url
  78. string referrer = "&referrer=";
  79. // This is where you override abstract class ProcessItem
  80. // Simply code here your custom logic which will be applied
  81. // on the list item
  82. public override void ProcessItem(SPListItem item)
  83. {
  84. // Store an item's ID before processing it
  85. itemGUIDs += item.UniqueId.ToString() + "_";
  86. // Only go to update metadata page after last item processed
  87. if (itemCount == 0)
  88. {
  89. string queryString = "meta=";
  90. // Construct query string
  91. // Assign common field internal names to query string
  92. // Updated metadata values need to be passed
  93. // from 'commonFields' dictionary of base class
  94. foreach (var pair in commonFields)
  95. queryString += pair.Key + "+";
  96. // Remove last '+' char
  97. queryString = queryString.Remove(queryString.LastIndexOf('+'));
  98. // Remove last '_' char
  99. itemGUIDs = itemGUIDs.Remove(itemGUIDs.LastIndexOf('_'));
  100. // Attach item IDs to query string
  101. queryString += itemGUIDs;
  102. // Get list id
  103. listID += item.ParentList.ID.ToString();
  104. // Attach list ID to query string
  105. queryString += listID;
  106. referrer += item.Web.Url;
  107. queryString += referrer;
  108. // Only go to update metadata page after last item processed
  109. SPUtility.Redirect(item.Web.Url + "/_layouts/Zieglers/BulkListActions/UpdateMetadata.aspx", SPRedirectFlags.Default, HttpContext.Current, queryString);
  110. } // end - if
  111. }
  112. } // end - class UpdateMetaDataHandler
  113. public class MoveItemsHandler : CustomHandlerBase
  114. {
  115. // Store item IDs to process
  116. string itemGUIDs = "IDs=";
  117. // Store list ID
  118. string listID = "&ListID=";
  119. // Store referrer url
  120. string referrer = "&referrer=";
  121. // This is where you override abstract class ProcessItem
  122. // Simply code here your custom logic which will be applied
  123. // on the list item
  124. public override void ProcessItem(SPListItem item)
  125. {
  126. // Move item
  127. // Store an item's ID before processing it
  128. itemGUIDs += item.UniqueId.ToString() + "_";
  129. // Only go to move page after last item processed
  130. if (itemCount == 0)
  131. {
  132. string queryString = "";
  133. // Remove last '_' char
  134. itemGUIDs = itemGUIDs.Remove(itemGUIDs.LastIndexOf('_'));
  135. // Attach item IDs to query string
  136. queryString += itemGUIDs;
  137. // Get list id
  138. listID += item.ParentList.ID.ToString();
  139. // Attach list ID to query string
  140. queryString += listID;
  141. referrer += item.Web.Url;
  142. queryString += referrer;
  143. // Only go to update metadata page after last item processed
  144. SPUtility.Redirect(item.Web.Url + "/_layouts/Zieglers/BulkListActions/Move.aspx", SPRedirectFlags.Default, HttpContext.Current, queryString);
  145. }
  146. }
  147. } // end - class MoveItemsHandler
  148. }