Sample code which will create a note and attach to the specified Entity (Specify Entity Name and GUID of the Entity Record)
CrmService service = GetCrmService("http://192.168.150.221:5555", "ORGANIZATION", "USERNAME", "PASSWORD", "DOMAIN");
annotation note = new annotation();note.subject = "NOTE SUBJECT";note.filename = @"schema.xsd";note.mimetype = "text/html";string encodedData = string.Empty;
using (FileStream fs = new FileStream(@"c:\schema.xsd", FileMode.Open, FileAccess.Read))
{byte[] byteData = new byte[fs.Length];
fs.Read(byteData, 0, byteData.Length);
encodedData = System.Convert.ToBase64String(byteData);
}
note.documentbody = encodedData;
note.objectid = new Lookup();note.objectid.type = "SPECIFY ENTITY_NAME";note.objectid.Value = new Guid("F27A627B-DF1A-DD11-AEA5-0003FF90FBC7");
note.objecttypecode = new EntityNameReference();note.objecttypecode.Value = "SPECIFY ENTITY_NAME";Guid annotationId = service.Create(note);
---- HERE you can Initialize CRM SERVICE Object.....
public static CrmService GetCrmService(string crmServerUrl, string organizationName, string userName, string password, string domain)
{ // Get the CRM Users appointments // Setup the Authentication Token CrmAuthenticationToken token = new CrmAuthenticationToken();token.OrganizationName = organizationName;
CrmService service = new CrmService();if (crmServerUrl != null &&
crmServerUrl.Length > 0)
{ UriBuilder builder = new UriBuilder(crmServerUrl); builder.Path = "//MSCRMServices//2007//CrmService.asmx";service.Url = builder.Uri.ToString();
}
service.Credentials = new System.Net.NetworkCredential(userName, password, domain);service.CrmAuthenticationTokenValue = token;
return service;}
Happy Coding....
0 comments:
Post a Comment