Tags


You may be in a situation to load thousands of documents onto a MOSS departmental site using the Upload Document feature.
 
The documents may be created as “checked out” to you (while you upload them) which means you have to go through page after page of selecting all documents and clicking “check in”. Come on, give me a break!
 
Is there any way to configure the document library so the documents uploaded are automatically checked in and not checked out? Or to “check-in” a complete document library. or may be say “take all the documents in this folder and check them in regardless of who has them checked out”?

Some of the options that you may try:-

1. If you haven’t uploaded documents yet, you could temporarily switch Yes to NO in “Require Check Out” section under shared document  -> settings –>Versioning Settings. Switch back to Yes when you done upload.

2. If the site is a publishing site, then you can use the Site Settings -> Site Administration -> Content and Structure tool to check in multiple documents at one time. Mass Check In of Documents:
http://sharepoint2007.microsoft.com/blogs/MarkE/Lists/Posts/Post.aspx?ID=15

3. Go by PowerShell way

The script in question looks like:
 
<#
.SYNOPSIS
Checks in files in a SharePoint document library.
.DESCRIPTION
The script checks in a single file or loops through a document library and checks in all files.
.PARAMETER url
Site URL.
.PARAMETER folder
Folder/Document library name
.PARAMETER file
File name
.PARAMETER comment
Version comment
.PARAMETER checkinType
Checkin type, can be: Major, Minor or Overwrite
.PARAMETER all
Checks out all files.
#>
param(
[string]$url,
[string]$folder,
[string]$file,
[string]$comment,
[string]$checkinType,
[switch]$all
)
# Check if Snap-in is loaded
if(-not(Get-PSSnapin | Where { $_.Name -eq “Microsoft.SharePoint.PowerShell”})) {
  Add-PSSnapin Microsoft.SharePoint.PowerShell;
}
# Use a switch to get checkin type, defaults to minor version if value not within range.
switch($checkinType) {
  {$_ -match “^major” } { $spCheckinType = [Microsoft.SharePoint.SPCheckinType]::MajorCheckIn; }
  {$_ -match “^minor” } { $spCheckinType = [Microsoft.SharePoint.SPCheckinType]::MinorCheckIn; }
  {$_ -match “^overwrite” } { $spCheckinType = [Microsoft.SharePoint.SPCheckinType]::OverwriteCheckIn; }
  Default { $spCheckinType = [Microsoft.SharePoint.SPCheckinType]::MinorCheckIn; }
}
$spWeb = Get-SPWeb $url
# Check if All files should be checked out
if ($all) {
  # Get the folder
  $spFolder = $spWeb.GetFolder($folder);
  # Store file collection in a variable
  $spFileCollection = $spFolder.Files;
  # Loop through files and check out if file is not already checked out
  $spFileCollection | ForEach-Object {
    # Check if file is not checked in
    if ($_.CheckOutType -ne “None”) {
      Try {
        $_.CheckIn($comment,$spCheckinType);
      } Catch {
        “You cannot overwrite a major version file”;
        $check = $true;
      } Finally {
        if ($check -eq $true) {
          Write-Host $_.Name Not Checked in;
        } else {
          Write-Host $_.Name checked in;
        }
        $check = $null;
      }
    } else {
      Write-Host $_.Name already checked in;
    }
  }
} else {
  # Store file URL in a variable
  $fileURL = $folder + “/” + $file;
  $spFile = $spWeb.GetFile($fileURL);
  # Check if file is not checked in
  if ($spFile.CheckOutType -ne “None”) {
    Try {
      $spFile.CheckIn($comment,$spCheckinType);
    } Catch {
      “You cannot overwrite a major version file”;
      $check = $true;
    } Finally {
      if ($check -eq $true) {
        Write-Host $spFile.Name Not Checked in;
      } else {
        Write-Host $spFile.Name checked in;
      }
      $check = $null;
    }
  } else {
    Write-Host $spFile.Name already checked in;
  }
}
$spWeb.Dispose()

In chapter 16 of the book, PowerShell for Microsoft SharePoint 2010 Administrators (ISBN: 9780071747974) there is a script for automating the procedure of checking in files in a document library. 

 The scripts can be downloaded from http://www.mhprofessional.com/getpage.php?c=computing_downloads.php&cat=112#P-R

About these ads