检入新添加到样式库的文件的sharepoint 2010事件接收器代码

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了检入新添加到样式库的文件的sharepoint 2010事件接收器代码相关的知识,希望对你有一定的参考价值。

Keep the namespace name, class name, guid that VS automatically generates. Make sure all of the "using" inclusions included.
  1. using System;
  2. using System.Runtime.InteropServices;
  3. using System.Security.Permissions;
  4. using Microsoft.SharePoint;
  5. using Microsoft.SharePoint.Security;
  6. using System.Linq;
  7.  
  8. namespace Lilly.Navigation2012.Features.Feature1
  9. {
  10. /// <summary>
  11. /// This class handles events raised during feature activation, deactivation, installation, uninstallation, and upgrade.
  12. /// </summary>
  13. /// <remarks>
  14. /// The GUID attached to this class may be used during packaging and should not be modified.
  15. /// </remarks>
  16.  
  17. [Guid("5253cb53-9e84-478d-b425-86d2cd8bc09b")]
  18. public class Feature1EventReceiver : SPFeatureReceiver
  19. {
  20. // Uncomment the method below to handle the event raised after a feature has been activated.
  21.  
  22. public override void FeatureActivated(SPFeatureReceiverProperties properties)
  23. {
  24. if (properties == null)
  25. {
  26. throw new ArgumentNullException("properties");
  27. }
  28.  
  29. SPSite site = properties.Feature.Parent as SPSite;
  30.  
  31. if (site != null)
  32. {
  33. SPWeb rootWeb = site.RootWeb;
  34.  
  35. // check in files
  36. SPList styleLibrary = rootWeb.Lists.TryGetList("Style Library");
  37. if (styleLibrary != null)
  38. {
  39.  
  40. var checkedOutFiles = from SPListItem item in styleLibrary.Items
  41. where string.Equals((string)item.Properties["FeatureId"], properties.Feature.DefinitionId.ToString(), StringComparison.OrdinalIgnoreCase)
  42. && (item.Level == SPFileLevel.Checkout || item.Level == SPFileLevel.Draft)
  43. select item;
  44.  
  45. foreach (SPListItem checkedOutFile in checkedOutFiles)
  46. {
  47. if (checkedOutFile.Level == SPFileLevel.Checkout)
  48. {
  49. // Check in a major version, not publishing enabled
  50. checkedOutFile.File.CheckIn(string.Empty, SPCheckinType.MajorCheckIn);
  51. }
  52. else if (checkedOutFile.Level == SPFileLevel.Draft)
  53. {
  54. // Publish files
  55. checkedOutFile.File.Publish(string.Empty);
  56. }
  57.  
  58. if (checkedOutFile.ModerationInformation != null && checkedOutFile.ModerationInformation.Status != SPModerationStatusType.Approved)
  59. {
  60. // Approve files
  61. SPFile file = checkedOutFile.Web.GetFile(checkedOutFile.File.UniqueId);
  62. file.Approve(string.Empty);
  63. }
  64. }
  65. }
  66. }
  67. }
  68.  
  69.  
  70. // Uncomment the method below to handle the event raised before a feature is deactivated.
  71.  
  72. //public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
  73. //{
  74. //}
  75.  
  76.  
  77. // Uncomment the method below to handle the event raised after a feature has been installed.
  78.  
  79. //public override void FeatureInstalled(SPFeatureReceiverProperties properties)
  80. //{
  81. //}
  82.  
  83.  
  84. // Uncomment the method below to handle the event raised before a feature is uninstalled.
  85.  
  86. //public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
  87. //{
  88. //}
  89.  
  90. // Uncomment the method below to handle the event raised when a feature is upgrading.
  91.  
  92. //public override void FeatureUpgrading(SPFeatureReceiverProperties properties, string upgradeActionName, System.Collections.Generic.IDictionary<string, string> parameters)
  93. //{
  94. //}
  95. }
  96. }

以上是关于检入新添加到样式库的文件的sharepoint 2010事件接收器代码的主要内容,如果未能解决你的问题,请参考以下文章

仅通过第二次单击即可使用JQuery和SharePointPlus js lib上传到SharePoint库的文件

SharePoint 文件大小限制

将 2 个简单的 aspx 页面添加到 Sharepoint 站点定义

如何设置文档库的权限以启用文件-> 仅在 sharepoint 2013 中的新选项

在文档库中添加自定义菜单项时的 SharePoint 问题

SharePoint Online 创建列表库