Solved

Sharepoint compulsory check-in comment

Posted on 2010-09-06
4
1,148 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
Comment Utility
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
Comment Utility

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
Comment Utility
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
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

SharePoint Designer 2010 has tools and commands to do everything that can be done with web parts in the browser, and then some – except uploading a web part straight into a page that is edited in SPD. So, can it be done? Scenario For a recent pr…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now