Create Outlook Filters using C# in Dynamics 365 CRM

Microsoft Dynamics 365 uses online synchronization filters to determine which records to synchronize between Dynamics 365 and Microsoft Outlook (using Microsoft Dynamics 365 for Outlook), or Exchange (using server-side synchronization). You can modify the existing online synchronization filters or create new filters to synchronize certain types of records. You can also delete, deactivate, or activate filters. You use the same set of filters (accessed through Dynamics 365 for Outlook) whether you’re synchronizing through Dynamics 365 for Outlook or server-side synchronization.

String contactName = String.Format(“offlineFilteredContact {0}”, DateTime.Now.ToLongTimeString());
String fetchXml =
String.Format(“<fetch version=\”1.0\” output-format=\”xml-platform\” mapping=\”logical\”><entity name=\”contact\”><attribute name=\”contactid\” /><filter type=\”and\”>” +
“<condition attribute=\”ownerid\” operator=\”eq-userid\” /><condition attribute=\”description\” operator=\”eq\” value=\”{0}\” />” +
“<condition attribute=\”statecode\” operator=\”eq\” value=\”0\” /></filter></entity></fetch>”, contactName);
SavedQuery filter = new SavedQuery();
filter.FetchXml = fetchXml;
filter.IsQuickFindQuery = false;
filter.QueryType = SavedQueryQueryType.OfflineFilters;
filter.ReturnedTypeCode = Contact.EntityLogicalName;
filter.Name = “ReadOnlyFilter_” + contactName;
filter.Description = “Sample offline filter for Contact entity”;
_offlineFilter = _serviceProxy.Create(filter);

For more info Read here.