magritton
9/15/2014 - 5:58 PM

This gets all of the items in all of the folders in a SharePoint Library. Note the CAML query and the limiting of items returned

This gets all of the items in all of the folders in a SharePoint Library. Note the CAML query and the limiting of items returned

 public void conductExtract()
        {
            ClientContext ci = new ClientContext("http://portal.opwftg.com/sites/OPWSS/Teams/OCM");
            List l = ci.Web.Lists.GetByTitle("PF");

            var oQuery =  new CamlQuery();
            oQuery.ViewXml = "<View Scope='Recursive'><Query><Where><Neq><FieldRef Name='ContentType' /><Value Type='Text'>Folder</Value></Neq></Where></Query><RowLimit>100</RowLimit></View>";
            ListItemCollection collListItems = l.GetItems(oQuery);

            ci.Load(collListItems);
            ci.ExecuteQuery();

            Console.WriteLine(collListItems.Count);
            int i = 0;
            foreach (ListItem oListItem in collListItems)
            {
                i++;
                if (oListItem["EmailSubject"] != null)
                {
                    string strText = oListItem["ID"].ToString() + "|";
                    strText += oListItem["EmailAttachmentCount"] == null?"": oListItem["EmailAttachmentCount"].ToString() + "|";

                    if (oListItem["EmailBodyHTML"] == null)
                        makeHtmlBodyFile(oListItem["ID"].ToString(), "");
                    else
                        makeHtmlBodyFile(oListItem["ID"].ToString(), oListItem["EmailBodyHTML"].ToString());

                    strText += oListItem["EmailCreationTime"] == null ? "" : oListItem["EmailCreationTime"].ToString() + "|";
                    strText += oListItem["EmailSenderEmailAddress"] == null ? "" : oListItem["EmailSenderEmailAddress"].ToString() + "|";
                    strText += oListItem["EmailSenderName"] == null ? "" : oListItem["EmailSenderName"].ToString() + "|";
                    strText += oListItem["EmailSubject"] == null ? "" : oListItem["EmailSubject"].ToString() + "|";
                    strText += oListItem["EmailMsgKey"] == null ? "" : oListItem["EmailMsgKey"].ToString() + "|";

                    if (oListItem["EmailBody"] == null)
                        makeBodyFile(oListItem["ID"].ToString(), "");
                    else
                        makeBodyFile(oListItem["ID"].ToString(), oListItem["EmailBody"].ToString());

                    strText += oListItem["EmailAttachmentNames"] == null ? "" : oListItem["EmailAttachmentNames"].ToString() + "|";
                    strText += oListItem["EmailRecipients"] == null ? "" : oListItem["EmailRecipients"].ToString() + "|";
                    strText += oListItem["EmailSentTime"] == null ? "" : oListItem["EmailSentTime"].ToString() + "|";
                    strText += oListItem["EmailTo"] == null ? "" : oListItem["EmailTo"].ToString() + "|";
                    strText += oListItem["EmailCC"] == null ? "" : oListItem["EmailCC"].ToString();
                    strText += Environment.NewLine;
                    System.IO.File.AppendAllText("C:\\StoredMsgs\\Metadata.txt",strText);
                }
                else
                {
                    Console.WriteLine("Nothing??");
                }
                Console.WriteLine(i);
            }
public void renameListItems(TextBox txtErrors,TextBox txtStatus)
        {
            ClientContext ci = new ClientContext("http://portal.opwftg.com/sites/OPWSS/Teams/OCM/Testing9-10");
            List l = ci.Web.Lists.GetByTitle("PublicFolderExport");
            CamlQuery qry = new CamlQuery();
            qry.ViewXml = "<View Scope='Recursive'><Query><Where><Neq><FieldRef Name='ContentType' /><Value Type='Text'>Folder</Value></Neq></Where></Query><RowLimit>100</RowLimit></View>";
            ListItemCollection lc = l.GetItems(qry);
            ci.Load(lc);
            ci.ExecuteQuery();
            txtStatus.Text = lc.Count.ToString() + Environment.NewLine;
            foreach (var item in lc)
            {
                if (item["EmailSubject"].ToString() != null)
                {
                txtStatus.Text += item["EmailSubject"].ToString() + Environment.NewLine;
                txtStatus.Text += item["FileLeafRef"].ToString() + Environment.NewLine;
                txtStatus.Text += "************************" + Environment.NewLine;
                }
            }
            MessageBox.Show("Completed");
            //try
            //{

            //    ListItemCreationInformation lci = new ListItemCreationInformation();
            //    ListItem li = l.AddItem(lci);
            //    li["Title"] = "Change - " + strTrackit;
            //    li["ChangeDate"] = strDate;
            //    li["TrackItNumber"] = strTrackit;
            //    li["ChangeInformation"] = strChange;
            //    li["ChangeKey"] = strKey;
            //    li.Update();
            //    ci.ExecuteQuery();
            //}
            //catch (System.Exception exx)
            //{
            //    tError.AppendText(exx.Message + Environment.NewLine);
            //}
        }