Solved

Sharepoint compulsory check-in comment

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need to pass a connection through class/Method 1 39
Two different visual studio versions 3 23
Export import database 4 43
Not showing JavaScript in the list 5 39
Summary In SharePoint 2010 it is easy to create custom color themes to jazz up a site. Theme colors can also be created in PowerPoint 2010 with a few clicks. But how do the chosen colors actually look in the SharePoint site? The attached PowerPoint…
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
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

896 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

17 Experts available now in Live!

Get 1:1 Help Now