Solved

Sharepoint compulsory check-in comment

Posted on 2010-09-06
4
1,170 Views
Last Modified: 2012-05-10
We are using versioning with content approval and check-in/out on all of our document libraries and would like to make check-in comments compulsory for all documents.

I believe that this is not possible out of the box but can be done using a custom event handler in C#.

I know how to create new SharePoint features but can someone please point me in the right direction of the specific code to use in Visual Studio for writing the DLL for the event handler?
0
Comment
Question by:PhilMacavity
  • 2
  • 2
4 Comments
 
LVL 7

Expert Comment

by:amolghanwat
ID: 33609501
I would say the best approach is to programatically check in all documents at regular intervals.
Check if a document is checked out and at mid night or during off hours check in all the documents.
Code can be found here:
http://bartvandenheede.blogspot.com/2008/02/programmaticaly-checkin-all-documents.html
Add this to scheduled jobs on the server and you are done.
I am looking at feature handlers and events it can recognize. If possible, I will re-post. Thanks.
0
 
LVL 7

Accepted Solution

by:
amolghanwat earned 500 total points
ID: 33609806

Create an event handler and bind it to a specific list template. You can add the following lines in the feature.xml file to bind the feature to a specific template.
e.g. <Receivers ListTemplateId="103">
Make sure that the feature is registered for ItemUpdated property. As you have mentioned, you are aware about creating a feature and activating it. Not going deep into it.
When you specify the template, you will find that the event handler takes into consideration every list with that template. So, have a loop and filter out the list that you want.
NOTE: This method is for SPListItem and not particularly at file level. So, even if someone does not modify the file, but modifies the item, the event should fire. This should be better as we are making sure that every modification done is monitored and the file is checked in.
In the code body, get the current item modified and check it in through code.
P.S. I have just written this code, but not tested it. Will try my best to test it today and see if this works. If you are able to test it and make it work, do let me know. Thanks.

using System;
using Microsoft.SharePoint;
namespace YOURNamespace
{
    public class Class_Name : SPItemEventReceiver
    {
       
 public override void ItemUpdated (SPItemEventProperties properties)

//*** Check in a Document (Minor Check in)
 SPListItem item = (SPListItem)SPContext.Current.Item;
 item.File.CheckIn("Checked in", SPCheckinType.MinorCheckIn);
//*** YOU CAN ALSO USE THE MAJOR CHECK IN IF REQUIRED.
            }
        }
    }
}

Reference:
How to get current list item:
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spcontext.aspx 
ItemUpdated event:
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spitemeventreceiver.itemupdated(v=office.12).aspx
0
 
LVL 1

Author Comment

by:PhilMacavity
ID: 33609834
Thanks amolghanwat,

That looks great.  I will try to test this later today and get back to you.
0
 
LVL 1

Author Closing Comment

by:PhilMacavity
ID: 33742101
Thanks for your help.  I am awarding you the points for pointing me in the right direction.  I ended up using some slightly different code which works using:
properties.AfterProperties ["vti_sourcecontrolcheckincomment"]

and

public override void ItemCheckingIn
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Icons on a page, side-by-side 6 44
C# bracket error 3 35
application restarter  - for an exe that hangs 9 30
Release Dynamically Allocated Memory in C# 3 37
For SharePoint sites, particularly public-facing ones, there are times when adding JavaScript, Meta Tags, CSS Styles or other content to the page <head> section is more practical than modifying master pages.  For instance, you could add the jQuery l…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question