I have an event receiver that creates/updates/deletes publishing pages in a publishing library.
In ItemUpdating, I get a handle to the page's underlying ListItem, change some of its properties and then update it. Finally I update the page, publish, and approve it.
var listItem = defaultPage.GetListItem();
defaultPage.CheckOut();
listItem[someField] = someValue;
listItem.Update();
defaultPage.Update();
defaultPage.CheckIn("Checked in on update.");
defaultPage.Publish("Published on update.");
defaultPage.Approve("Approved on update.");
This all works great when the page status is Published - I determine that by checking the value of listItem.File.Level.
There are three other scenarios that I need to work with:
1. The page is checked out, but not changed or saved back.
If the user checked out the page but didn't make any changes, I can call defaultPage.UndoCheckOut(); and continue on. In this case, Level is SPFileLevel.Checkout.
2. The user checked out the page, made some changes, saved them, but didn't check the page back in
If the user checked out the page, made some changes and saved them, Level is still SPFileLevel.Checkout, but the call to listItem.Update(); fails with the following exception.
The file Pages/default.aspx has been modified by DOMAIN\User
3. The user checked the page back in after making changes.
Here, Level is SPFileLevel.Draft, I can simply check out the file and do what I need to do.
Any thoughts on getting around the issue in #2?

CheckInand then proceed as normal with theUpdate? – Kit Menke♦ Jun 22 '11 at 21:37