How can I find corrupt files in a SharePoint 2013 ListItemCollection using CSOM
<p>I have a CSOM program that transfers hundreds PDF files into SharePoint 2013 libraries. Once in a while one of those transferred files will be corrupt and can't be opened. The source file is good and the same file can be opened after having been transferred to other libraries but in one random library it will be corrupt.
I want to loop through the libraries, find the corrupt files and delete them but how can I tell using CSOM if the file is corrupt? I tried looping through and using File.OpenBinaryStream() but that succeeds on the corrupt files. Below is the code that reads the library and loops through the files. Any suggestions would be appreciated.</p>

<pre><code>                    using (ClientContext destContext = new ClientContext(clientSite.Value))
                {
                    destContext.AuthenticationMode = ClientAuthenticationMode.FormsAuthentication;
                    destContext.FormsAuthenticationLoginInfo = new FormsAuthenticationLoginInfo(ClientSiteUsername, ClientSitePassword);

                    // get the new list
                    Web destWeb = destContext.Web;
                    ListCollection lists = destWeb.Lists;
                    List selectedList = lists.GetByTitle(clientLibraryName);
                    destContext.Load(lists);
                    destContext.Load(selectedList);
                    ListItemCollection clientCurrentItemsList = selectedList.GetItems(CamlQuery.CreateAllItemsQuery());

                    destContext.Load(clientCurrentItemsList,
                                       eachItem =&gt; eachItem.Include(
                                       item =&gt; item,
                                       item =&gt; item["ID"],
                                       item =&gt; item["FileLeafRef"]));

                    try
                    {
                        destContext.ExecuteQuery();
                    }
                    catch (Exception ex)
                    {
                        log.Warn(String.Format("Error in VerifyClientDocuments. Could not read client library: {0}", clientSite.Value), ex);
                        continue;
                    }

                    foreach (ListItem item in clientCurrentItemsList)
                    {
                        try
                        {
                            item.File.OpenBinaryStream();
                        }
                        catch (Exception ex)
                        {
                            var val = ex.Message;
                            //delete here
                        }

                    }
                }
</code></pre>