Hi
I have an asp.net mvc app that connects to CRM to attach notes. Here is the code I use to attache file:
//File is of type HttpPostedFileType byte[] file = new byte[File.ContentLength]; File.InputStream.Read(file, 0, file.Length); var mimetype=File.ContentType; Entity objNewEntity = new Entity("annotation"); objNewEntity["subject"] = title; objNewEntity["objectid"] = new EntityReference(entitiyname, id); objNewEntity["objecttypecode"] = entitiyname; objNewEntity["documentbody"] = Convert.ToBase64String(file); objNewEntity["filename"] = filename; objNewEntity["mimetype"] = mimetype;
service.Create(objNewEntity);
and here is how I read the attachment :
model.Attachment = Convert.FromBase64String(annotation.Attributes["documentbody"].ToString()); model.FileName = annotation.Attributes["filename"].ToString(); model.MimeType = annotation.Attributes["mimetype"].ToString();
It saves all file, but when I download the file, only TXT file types are shown and png or jpg file are not shown in windows. I mean the file have size, but when I open it, windows 10 shows "We Can not open this file"
Would you help me please ?
*This post is locked for comments
Hi. You should convert the documentbody (attachment) to base64string.
Like explained here: www.google.at/.../amp
br Thomas
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156