Sunday, August 1, 2010

Check if Page is already checked out

It is very helpful while editing the contents of a publishing page to check if desired page is already checked or not.

Here is is the code to check this

Sol 1:

if (pPage.ListItem.File.CheckOutType == SPFile.SPCheckOutType.None)
pPage.CheckOut();

Sol 2:

SPFile fileSource = web.GetFile(strSourceFilePath);
SPUser user = null;
user = fileSource.CheckedOutBy;

if (user != null)
{....


If we does not check so then we may get error that page is already checked out.

No comments: