Paging through Query Expression to retrieve more than 5000 records

Paging through Query Expression to retrieve more than 5000 Records.

QueryExpression query = ner QueryExpression(“contact”);
            query.ColumnSet = new ColumnSet(false);
            query.PageInfo = new PagingInfo();
            query.PageInfo.Count = 5000;
            query.PageInfo.PageNumber = 1;
            query.PageInfo.ReturnTotalRecordCount = true;
            EntityCollection entityCollection = service.RetrieveMultiple(query);
            EntityCollection final = new EntityCollection();
            foreach (Entity i in entityCollection.Entities)
            {
                final.Entities.Add(i);
            }
            do
            {
                query.PageInfo.PageNumber += 1;
                query.PageInfo.PagingCookie = entityCollection.PagingCookie;
                entityCollection = service.RetrieveMultiple(query);
                foreach (Entity i in entityCollection.Entities)
                    final.Entities.Add(i);
            }
            while (entityCollection.MoreRecords);
Total records are stored in a final collection.
That’s It. Enjoy 🙂
Advertisements

Writing Logs into a Internal Storage Text File

Writing Logs into a Internal Storage Text File :

//Write Log Files to Internal Storage
Public void WriteLog(string messages)
{
 String currentdate = DateTime.Now.Date.ToString("dd-MM-YY");
//Internal storage Path
 string path = string.Format(@"E:\CRMLOGS\{0}_log.txt", currentdate); 
 if (!File.Exists(path))
 {
    File.Create(path);
 }
TextWriter writer = new StreamWriter(path);
 writer.WriteLine(messages);
 writer.Close();
}

That’s It. Enjoy 🙂