Sharepoint Client Object Model Check Document Library is available or not

To check Document Library availability in SharePoint from Client Object Model

private bool ValidateSPLibrary(string DocumentLibrary)
{
using (ClientContext clientContext = new ClientContext(SharepointSite))
{
try
{
List existingList;

Microsoft.SharePoint.Client.Web web = clientContext.Web;

ListCollection lists = web.Lists;

IEnumerable<List> existingLists = clientContext.LoadQuery(
lists.Include(
list => list.Title)
);
clientContext.ExecuteQuery();

existingList = existingLists.FirstOrDefault(list => list.Title.ToLower() == DocumentLibrary.ToLower());

if (existingList != null)
{
return true;
}
else
{
return false;
}
}
catch (Exception exception)
{
ShowErrorMessage(exception.ToString());

return false;
}
}
}

 

Advertisement

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 )

Twitter picture

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

Facebook photo

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

Connecting to %s