Solved

Sharepoint compulsory check-in comment

Posted on 2010-09-06
4
1,182 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

We had a requirement to extract data from a SharePoint 2010 Customer List into a CSV file and then place the CSV file into a directory on the network so that the file could be consumed by an AS400 system. I will share in Part 1 how to Extract the Da…
I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

752 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