Solved

Sharepoint compulsory check-in comment

Posted on 2010-09-06
4
1,166 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
SharePoint List Calculated Field 4 34
What namespace do I need to import? 2 29
HttpPostedFile 1 26
VB.NET 2008 Winforms Signing 13 19
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…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

777 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