WSS Practice: Checking in/out Documents, and Versioning

Well, for the WSS application developer exam, you’re supposed to know about programmatically checking in and out documents:

//*** Check out a document
Console.WriteLine("Check out {0}", myItem["Name"]);
//*** Check in a Document (Minor Check in)
myItem.File.CheckIn("Checked in Programmatically", SPCheckinType.MinorCheckIn );
Console.WriteLine("Item Checked in");

One should also be able to list all versions of a document:

//*** List all versions of a document
foreach (SPFileVersion ver in myItem.File.Versions)
Console.WriteLine(" - v{0} ({1})", ver.VersionLabel, ver.CheckInComment);

And restore a version:

//*** Restore to version 1.0
myItem.File.CheckIn("Restored by Program to v1.0");
Console.WriteLine("{0} restored to v1.0", myItem.Name);

All pretty straight forward.

WSS Practice: Checking in/out Documents, and Versioning

One thought on “WSS Practice: Checking in/out Documents, and Versioning

  1. Antonio says:

    Great blog entry. One tidbit to add, if you want the restored version to be the “current” live verions, you need to publish it after the item.file checkin.
    This is helpfull for when you want to restore the live version of pages to a version before date x.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.