public class CancelPublishMajorVersionTest : SPItemEventReceiver
{
private HttpContext current;
public CancelPublishMajorVersionTest () : base()
{
current = HttpContext.Current;
}
public override void ItemUpdating(SPItemEventProperties properties)
{
base.ItemUpdating(properties);
if (current != null)
{
//check if request is coming from the MS office not from the browser
if ((current.Request != null && current.Request.CurrentExecutionFilePath != null && current.Request.CurrentExecutionFilePath.IndexOf("_vti_bin") > -1) || (current.Request.CurrentExecutionFilePath.Equals("/_layouts/checkin.aspx")))
{
String sLevel = Convert.ToString(properties.AfterProperties["vti_level"]);
//2 for Publish as major version and 1 for Checkin as major version
if (sLevel == "2" || sLevel == "1")
{
properties.Status = SPEventReceiverStatus.CancelWithError;
properties.ErrorMessage = "Publish Major Version not allows";
properties.Cancel = true;
}
}
}
}
}
Comments
Post a Comment