检入新添加到样式库的文件的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.
using System; using System.Runtime.InteropServices; using System.Security.Permissions; using Microsoft.SharePoint; using Microsoft.SharePoint.Security; using System.Linq; namespace Lilly.Navigation2012.Features.Feature1 { /// <summary> /// This class handles events raised during feature activation, deactivation, installation, uninstallation, and upgrade. /// </summary> /// <remarks> /// The GUID attached to this class may be used during packaging and should not be modified. /// </remarks> [Guid("5253cb53-9e84-478d-b425-86d2cd8bc09b")] public class Feature1EventReceiver : SPFeatureReceiver { // Uncomment the method below to handle the event raised after a feature has been activated. public override void FeatureActivated(SPFeatureReceiverProperties properties) { if (properties == null) { } SPSite site = properties.Feature.Parent as SPSite; if (site != null) { SPWeb rootWeb = site.RootWeb; // check in files SPList styleLibrary = rootWeb.Lists.TryGetList("Style Library"); if (styleLibrary != null) { var checkedOutFiles = from SPListItem item in styleLibrary.Items where string.Equals((string)item.Properties["FeatureId"], properties.Feature.DefinitionId.ToString(), StringComparison.OrdinalIgnoreCase) && (item.Level == SPFileLevel.Checkout || item.Level == SPFileLevel.Draft) select item; foreach (SPListItem checkedOutFile in checkedOutFiles) { if (checkedOutFile.Level == SPFileLevel.Checkout) { // Check in a major version, not publishing enabled checkedOutFile.File.CheckIn(string.Empty, SPCheckinType.MajorCheckIn); } else if (checkedOutFile.Level == SPFileLevel.Draft) { // Publish files checkedOutFile.File.Publish(string.Empty); } if (checkedOutFile.ModerationInformation != null && checkedOutFile.ModerationInformation.Status != SPModerationStatusType.Approved) { // Approve files SPFile file = checkedOutFile.Web.GetFile(checkedOutFile.File.UniqueId); file.Approve(string.Empty); } } } } } // Uncomment the method below to handle the event raised before a feature is deactivated. //public override void FeatureDeactivating(SPFeatureReceiverProperties properties) //{ //} // Uncomment the method below to handle the event raised after a feature has been installed. //public override void FeatureInstalled(SPFeatureReceiverProperties properties) //{ //} // Uncomment the method below to handle the event raised before a feature is uninstalled. //public override void FeatureUninstalling(SPFeatureReceiverProperties properties) //{ //} // Uncomment the method below to handle the event raised when a feature is upgrading. //public override void FeatureUpgrading(SPFeatureReceiverProperties properties, string upgradeActionName, System.Collections.Generic.IDictionary<string, string> parameters) //{ //} } }
以上是关于检入新添加到样式库的文件的sharepoint 2010事件接收器代码的主要内容,如果未能解决你的问题,请参考以下文章
仅通过第二次单击即可使用JQuery和SharePointPlus js lib上传到SharePoint库的文件
将 2 个简单的 aspx 页面添加到 Sharepoint 站点定义