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"]);
myItem.File.CheckOut();
Console.ReadLine();
//*** Check in a Document (Minor Check in)
myItem.File.CheckIn("Checked in Programmatically", SPCheckinType.MinorCheckIn );
Console.WriteLine("Item Checked in");
Console.ReadLine();

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

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

And restore a version:

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

All pretty straight forward.

Advertisements
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:

WordPress.com Logo

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

Google+ photo

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

Twitter picture

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

Facebook photo

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

w

Connecting to %s

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