Create Note Entity Record

 

ServerConnection serverConnect =

 

 

new ServerConnection();

 

ServerConnection.Configuration config = serverConnect.GetServerConfiguration();

 

OrganizationServiceProxy _serviceProxy;

 

 

 

var creds = new ClientCredentials();

 

 

 

using (_serviceProxy = new OrganizationServiceProxy(config.OrganizationUri,

 

config.HomeRealmUri,

 

config.Credentials,

 

config.DeviceCredentials))

 

{

 

 

 

// This statement is required to enable early-bound type support.


_serviceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(

 

 

new ProxyTypesBehavior());

 

IOrganizationService service = (IOrganizationService)_serviceProxy;

 

_serviceProxy.EnableProxyTypes();

 

 

 

using (Microsoft.Crm.Sdk.CustomService.serviccontext srv = new Microsoft.Crm.Sdk.CustomService.serviccontext(_serviceProxy))

 

{

 

EntityReference objid =

 

 

new EntityReference();

 

 

 

string _subject = “Note Created on “ + DateTime.Now.ToString();

 

 

 

string _notetext = “Note Created on “ + DateTime.Now.ToString();

 

 

 

string _objecttypecode = string.Empty;

 

EntityReference _acc =

 

 

new EntityReference(Account.EntityLogicalName, newGuid(_accountid));

 

objid = _acc;

 

_objecttypecode = Account.EntityLogicalName;

 

 

 

// Add a note with a document attachment to the contact’s record.


 

 

var attachment = File.OpenRead(fuAttachment.PostedFile.FileName);

 

 

 

var data = newbyte[attachment.Length];

 

attachment.Read(data, 0, (

 

 

int)attachment.Length);

 

 

 

var note = new Microsoft.Crm.Sdk.CustomService.Annotation()

 

{

 

DocumentBody =

 

 

Convert.ToBase64String(data),

 

FileName = Path.GetFileName(attachment.Name),

 

MimeType = GetMimeType(attachment.Name),

 

Id =

 

 

Guid.NewGuid(),

 

Subject = _subject,

 

NoteText = _notetext,

 

ObjectId = objid,

 

ObjectTypeCode = _objecttypecode

 

};

 

 

 

Guid _annotationId = note.Id;

 

srv.AddObject(note);

 

srv.SaveChanges();

 

}

 

}

 

 

private

 

 

string GetMimeType(string fileName)

{

 

string mimeType = “application/unknown”;

 

string ext = System.IO.Path.GetExtension(fileName).ToLower();

Microsoft.Win32.

 

RegistryKey regKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(ext);

 

if (regKey != null && regKey.GetValue(“Content Type”) != null)   

mimeType = regKey.GetValue(

 

“Content Type”).ToString(); return mimeType;

}

 

This entry was posted in MS Dynamic CRM 2011. Bookmark the permalink.

11 Responses to Create Note Entity Record

  1. Thank you for your time and energy to have put these things together on this web site. Janet and I very much valued your ideas through your articles with certain things. I’m sure that you have several demands in your timetable hence the fact that a person like you took equally as much time like you did to help people just like us by way of this article is actually highly valued.

  2. The recommendations you contributed here are really precious. It absolutely was such a pleasurable surprise to see that waiting for me once i woke up today. They are continually to the point and straightforward to interpret. Thanks for your time for the thoughtful ideas you’ve shared in this article.

  3. I can’t thank you adequately for the articles on your web-site. I know you add a lot of time and effort into all of them and truly hope you know how much I appreciate it. I hope I am able to do something identical for another person someday.

  4. The points you contributed here are really precious. It turned out such a fun surprise to have that awaiting me once i woke up this very day. They are always to the point plus easy to understand. Thank you for the clever ideas you’ve got shared in this article.

  5. I cannot thank you enough for the content on your site. I know you put a lot of time and energy into all of them and hope you know how much I appreciate it. I hope I will do the identical thing for someone else at some point.

  6. I can not thank you fully for the posts on your website. I know you add a lot of time and effort into these and truly hope you know how deeply I enjoy it. I hope I could do a similar thing for someone else one of these days.

  7. goal in life says:

    I couldn’t currently have asked for a better blog. You happen to be always there to give excellent advice, going on to the point for quick understanding of your subscribers. You’re undoubtedly a terrific expert in this matter. Thank you for always being there for visitors like me.

  8. It can be rare to get a professional person in whom you might have some confidence. In the world nowadays, nobody actually cares about showing others the answer in this matter. How blessed I am to have actually found a wonderful website as this. It is really people like you who make a genuine difference currently through the suggestions they write about.

  9. I can not thank you more than enough for the posts on your website. I know you set a lot of time and energy into all of them and hope you know how much I appreciate it. I hope I can do the identical thing for someone else someday.

  10. The points you shared here are very useful. It absolutely was such an enjoyable surprise to have that waiting for me once i woke up now. They are generally to the point and easy to interpret. Thank you very much for the thoughtful ideas you have shared in this article.

  11. Thanks a lot for your efforts to have had these things together on this website. John and i also very much appreciated your knowledge through your own articles over certain things. I’m sure that you have quite a few demands in your program therefore the fact that you took all the time like you did to guide people really like us via this article is even highly liked.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>