Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Problem with image file attachment to note using SDK

Posted on by Microsoft Employee

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

  • Suggested answer
    tpeschat Profile Picture
    tpeschat 4,926 on at
    RE: Problem with image file attachment to note using SDK

    Hi. You should convert the documentbody (attachment) to base64string.

    Like explained here: www.google.at/.../amp

    br Thomas

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans