Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Read attachment body in dynamics crm using c#

Posted on by

How to read text/string value from docx email-activity attachment  without downloading the file in dynamics crm.

*This post is locked for comments

  • Suggested answer
    RE: Read attachment body in dynamics crm using c#

    Ok I realised that its a 1 year old post :) , any ways hope this will help any one who will be looking for similar solution.

    Hi,

       That code is actually getting word content in to byte, now you can use something like Novacode docx library to read.

       using Novacode;

        ......

       ..................

    ...........................

         var mandatoryDocument = DocX.Load(byte[]); //in place of byte[] the bytes you read from document.

      Hope it will help you.

    Kind Regards

    Prashanth

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: Read attachment body in dynamics crm using c#

    We can tell you how to use CRM SDK to correctly extract the contents of that attachment, but not necessarily how to parse a word document in your code. This might be a question you can get answered faster at stackoverflow (or C# forums)

  • ganeshm Profile Picture
    ganeshm on at
    RE: Read attachment body in dynamics crm using c#

    so my scenario is like when i get a email attachment,i need to read text values from the attachment(using docx & excel types)

  • ganeshm Profile Picture
    ganeshm on at
    RE: Read attachment body in dynamics crm using c#

    thanks for the reply,

    That my problem without saving or creating a word document using that value, how to get the the string values present in the encoded files?Is there any way to get the string value ?

  • David Jennaway Profile Picture
    David Jennaway 14,063 on at
    RE: Read attachment body in dynamics crm using c#

    This probably aren't 'junk values' - this is the body of the document. Word documents need to be parsed by software that understands the document format, i.e. Microsoft Word

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Read attachment body in dynamics crm using c#

    Hello,

    Check this article, it should help you to find an answer - http://lmgtfy.com/?s=b&iie=1&q=read+docx+file+in+c%23

  • ganeshm Profile Picture
    ganeshm on at
    RE: Read attachment body in dynamics crm using c#

                         for3.png

    My .doc file attachment get encode in my 'activityattachment' . so using c# i can get the 'body' value .but using that value i cant get the text/string directly.

    i tired using,

    var encode= ent.Attributes["body"].ToString();
    byte[] byt = Convert.FromBase64String(encode);
    string decodedString = Encoding.UTF8.GetString(byt);

     in "decodedstring" i am getting the some junk values(pic in above post).

  • Suggested answer
    Gee Bee Profile Picture
    Gee Bee 11,397 on at
    RE: Read attachment body in dynamics crm using c#

    Hi

    It looks like it is working, as you can see the content displayed.

    string fileName = (string)annotationFRI.Attributes["filename"];
    
                                
                                string noteText = (string)annotationFRI.Attributes["notetext"];
                                string documentBody = (string)annotationFRI.Attributes["documentbody"];
    
                                byte[] fileContent = Convert.FromBase64String(documentBody);
  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Read attachment body in dynamics crm using c#

    Thanks for sharing the reference, Mohd.

  • ganeshm Profile Picture
    ganeshm on at
    RE: Read attachment body in dynamics crm using c#

    thanks for reply,

    it doesnt work.

    for2.png

    In my requirement i have to read the text/string value directly from the encoded document without downloading or saving the file.

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,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans