locked
Problem saving e-mail attachment with MS CRM 4.0 RRS feed

  • Question

  •  Hi.

    I have MIME e-mail message in multi-part format. It has an XML file attached:


    ------=_NextPart_000_007A_01C98582.2EB0A120
    Content-Type: text/xml;
    name="regform.xml"
    Content-Transfer-Encoding: quoted-printable
    Content-Disposition: attachment;
    filename="regform.xml"

    <?xml version=3D"1.0" encoding=3D"UTF-8"?><?mso-infoPathSolution =
    ...
    s1:Header><ns1:General><ns1:ent_full_name>=D0=9E=D0=B1=D1=89=D0=B5=D1=81=D1=
    =82=D0=B2=D0=BE =D1=81 =


    The source encoding of this file was UTF-8. Here you can see starting national (russian) characters wich 2-byte pairs are escaped by codes. I'm trying to extract attached XML file as byte[] data an save it to disk:

    BusinessEntity[] attachments;      
    activitymimeattachment currentAttachment;      
    MimeEmailMessage mime;      
          
    System.Diagnostics.EventLog eventLog = new System.Diagnostics.EventLog();      
    eventLog.Source = "MySource";      
          
    ServiceLogger serviceLogger;      
    serviceLogger = new ServiceLogger(eventLog, LogLevel.Normal, "sl.log");      
          
    mime = new MimeEmailMessage(msgData, serviceLogger);      
    attachments = mime.GetAttachments();      
    foreach (BusinessEntity be in attachments)      
    {      
        byte[] data;      
          
        currentAttachment = (activitymimeattachment)be;      
        data = Convert.FromBase64String(currentAttachment.body);      
        // FileName = ...      
        using (FileStream fs = new FileStream(FileName, FileMode.Create))      
        {      
            fs.Write(data, 0, Data.Length);      
            fs.Close();      
        }      

    When I open saved files I see that national characters are replaced by "?" and some other symbols. What I did wrong?
    Tuesday, February 3, 2009 7:40 AM

Answers

  • Did you find an answer to this?  I find that XML files can be a problem--can't email them with Outlook and they can be hard to save as attachments.  One fix is to save as a .txt file.
    Monday, April 27, 2009 10:20 AM
    Moderator