Hi,
1. Create one console application
2. replace the below code in Program.cs file
3. Add reference of Microsoft.Xrm.Sdk.dll, Microsoft.Xrm.Client.dll
***************************************************
using Microsoft.Xrm.Client;
using Microsoft.Xrm.Client.Services;
using Microsoft.Xrm.Sdk;
using System;
namespace CRMCustomDemo
{
class Program
{
static void Main(string[] args)
{
try
{
// for crm online instance
CrmConnection connection = CrmConnection.Parse("URL=https://****.crm5.dynamics.com/; username=***@***.com; password=****");
OrganizationService _service = new OrganizationService(connection);
var fetchXML = "<fetch distinct=\"true\" mapping=\"logical\" output-format=\"xml-platform\" version=\"1.0\" >";
fetchXML += "<entity name=\"opportunity\">";
fetchXML += " <attribute name=\"name\" />";
fetchXML += " <link-entity name=\"annotation\" from=\"objectid\" to=\"opportunityid\" alias=\"an\" link-type=\"outer\" >";
fetchXML += " <attribute name=\"objectid\" />";
fetchXML += " <filter type=\"and\" >";
fetchXML += " <condition attribute=\"isdocument\" value=\"1\" operator=\"eq\" />";
fetchXML += " </filter>";
fetchXML += " </link-entity>";
fetchXML += " <filter type=\"and\" >";
fetchXML += " <condition entityname=\"an\" attribute=\"objectid\" operator=\"null\" />";
fetchXML += " </filter>";
fetchXML += " </entity>";
fetchXML += "</fetch>";
Entity entity = new Entity("savedquery");
entity["name"] = "NoAttachmentsView";
entity["fetchxml"] = fetchXML;
entity["returnedtypecode"] = "opportunity";
entity["querytype"] = 0;
_service.Create(entity);
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}
If you couldn't get it done, please drop a mail to me @ manirajcareer@live.com will share you the solution file.