Wednesday, 28 May 2014

Checkout a document in SharePoint using Object Model Code

SPSite siteCollection = null;
SPWeb topLevelSite = null;
string strDocLibraryLink = System.Configuration.ConfigurationManager.AppSettings["SPDocumentLibrary"].ToString();//"http://*******/Documents/"; siteCollection = new SPSite(strDocLibraryLink);
topLevelSite = siteCollection.AllWebs[ConfigurationManager.AppSettings["TopLevelSite"].ToString()];// siteCollection.AllWebs["Corporate/DealDesk"];
SPList list = topLevelSite.Lists["Documents"]; //topLevelSite.Lists["Approved Documents"];
foreach (SPListItem item in list.Items)
{
if (Convert.ToString(item["Document Number"]).Equals(strDocNumber))//It should be document ID. We need to add. lnkDocumentId
{
SPFileName.CheckOut(true, Convert.ToString(System.DateTime.Now));
}
}