none
How to Change BizTalk Message Body Part Attachment File Name?

    Question

  • Hi,

     

    How to Change BizTalk Message Body Part Attachment File Name?

     

    I'm always receiving body.xml file name as attachment.

     

    I've tried Message(MIME.FileName) = "myfilename.xml" , but it hasn't worked.

     

    Regards,

     

    Maciej

    Wednesday, December 05, 2007 11:52 AM

Answers

  • I have done this based upon a pattern that was built/described by Stephen Thomas.  You can find his blog post here:

    http://www.biztalkgurus.com/blogs/biztalk/archive/2006/08/08/How-to-Split-Received-Email-Attachments-in-BizTalk-2006.aspx

     

    Here is a small excerpt of my code from within message construction shape.  My code varies a little from the example.

     

    //First, I assign an inbound message which is of type (XML) to a message of type Microsoft.XLANGs.BaseTypes.XLANGMessage

     

    xlangContainer = msgEmailIn;

     

    //I also get the the number of parts in the XLangMessage, Part 0 is always the body

    PartCount = xlangContainer.Count;

     

    //I then loop through all parts of inbound message.  Each additional part represents an attachment

     

    // xlangContainer is of Type Microsoft.XLANGs.BaseTypes.XLANGMessage

    //msgAttachment is of type System.Xml.XmlDocument

    msgAttachment = xlangContainer[attachmentCounter];

     

    //This is required inorder to perserve the original attachment name

    //xlangPartContainer  is of TypeMicrosoft.XLANGs.BaseTypes.XLANGPart

    xlangPartContainer = xlangContainer[attachmentCounter];

     

     

    msgAttachment(FILE.ReceivedFileName) = xlangPartContainer.Name;

     

    In my example I wanted to preserve the original name of the attachment. But, you could insert what ever you wanted.

     

    If you need some more info about the Email splitting process, reply back and I will be happy to help out.

     

    Friday, January 04, 2008 7:14 PM
    Answerer

All replies

  • The attachments should preserve their name, not sure why they have the name “body.xml”. One thought is that you set the “Body Part Index” value to something else than 0 in which case the body becomes an attachment and one of the attachment become the body. If this is not the case, please take a look at this blog: http://blogs.msdn.com/richardbpi/archive/2006/02/14/532190.aspx and see if it helps. If this does not help, please describe in more details your scenario, receive location settings, if you can send the orchestration/project it will help and I am going to take a look.

     

    Nicu

    Friday, January 04, 2008 6:08 PM
  • I have done this based upon a pattern that was built/described by Stephen Thomas.  You can find his blog post here:

    http://www.biztalkgurus.com/blogs/biztalk/archive/2006/08/08/How-to-Split-Received-Email-Attachments-in-BizTalk-2006.aspx

     

    Here is a small excerpt of my code from within message construction shape.  My code varies a little from the example.

     

    //First, I assign an inbound message which is of type (XML) to a message of type Microsoft.XLANGs.BaseTypes.XLANGMessage

     

    xlangContainer = msgEmailIn;

     

    //I also get the the number of parts in the XLangMessage, Part 0 is always the body

    PartCount = xlangContainer.Count;

     

    //I then loop through all parts of inbound message.  Each additional part represents an attachment

     

    // xlangContainer is of Type Microsoft.XLANGs.BaseTypes.XLANGMessage

    //msgAttachment is of type System.Xml.XmlDocument

    msgAttachment = xlangContainer[attachmentCounter];

     

    //This is required inorder to perserve the original attachment name

    //xlangPartContainer  is of TypeMicrosoft.XLANGs.BaseTypes.XLANGPart

    xlangPartContainer = xlangContainer[attachmentCounter];

     

     

    msgAttachment(FILE.ReceivedFileName) = xlangPartContainer.Name;

     

    In my example I wanted to preserve the original name of the attachment. But, you could insert what ever you wanted.

     

    If you need some more info about the Email splitting process, reply back and I will be happy to help out.

     

    Friday, January 04, 2008 7:14 PM
    Answerer
  • Hi Kent,

    I used your code snippet and I can't get it to work.  I still get the Guid file name when "send" the message.  Here's a bit of my code.  Also, oXMsgPart stays "null" throughout in debug ???.

     

    First,

    /*

    oXMessage is of Microsoft.XLANGs.BaseTypes.XLANGMessage

    mEmailIn is of System.Xml.XmlDocument

    */

    oXMessage = mEmailIn;

    nCount = oXMessage.Count;

    /*

    And then, loop:

    oXMsgPart is of Microsoft.XLANGs.BaseTypes.XLANGPart

    oXMessage is of Microsoft.XLANGs.BaseTypes.XLANMessage

    mAttachOut if System.Xml.XmlDocument

    */

    mAttachOut = oXMessageNo;

    oXMsgPart = oXMessageNo;

    mAttachOut(FILE.ReceivedFileName) = oXMsgPart.Name;

    n = n + 1;     // init 1

    ...

    send mAttachOut

     

    Ultimately, the attachments are .zip files that I need to unzip.  I call an external assembly to do that.  I haven't figured out how to pass the file to the utility.

    Any ideas, Thanks.

    Tuesday, December 02, 2008 6:53 PM
  •  

    Hi Jacques,

     

    Within BizTalk Admin console, how have you configured your Send Port - FileName property(The one that you use to send mAttachOut)?  Are you using %MessageID%.xml?  If so, you will want to change it to %SourceFileName%.  %SourceFileName% is the BizTalk Macro that will use the Received File Name when writing out the file.

     

    If I am complete off, here please post some additional details.

     

    Kent

    Thursday, December 04, 2008 6:20 PM
    Answerer

  • Hello, I´m having a similar problem. I used the discussed approach and found two problems:

    1º in a specific message type (when sending a mail using outlook - rich text format) with one attachment (only one) the IN_MSG will only have ONE part. If more attachments are sent this problem will not ocurr. This situation only happens when the mail has no text in the body. Still, an annoying problem.

    2º I need to extract the name of each attachment. I use the property Name from the XLangPart to get the attachment name. But... in some cases i cannot extract this information (a GUID appears instead of the file name...)

    Can anyone help me?

    Thank you.

    Thursday, December 11, 2008 12:17 PM
  •  BizTalk uses the following logic to get the file name:

    1. Take it from the Content-Description header. Some vendors don't populate the Content-Description header in the message sent to Exchange.
    2. If not found, then the part name is based on the Content-ID header.
    3. If still not found, then generate a GUID for the part name.

    To access the attachment file name within a custom MIME pipeline component, use the "FileName" property in the
    "<http://schemas.microsoft.com/BizTalk/2003/mime-properties>" namespace. The solution is a combination of two things. First, use messagePart.Name when looking at a message part. Then, after you assign that part to a new message, the calling orchestration needs a reference to the FILE.ReceivedFileName property of the message.

    To access the attachment file name within an orchestration, use the "FileName" property in the "<http://schemas.microsoft.com/BizTalk/2003/mime-properties>"
    namespace. Sample code:

    Doesn't Work:
    Out(FILE.ReceivedFileName) = MsgPart.Name

    Works:
    Out(FILE.ReceivedFileName) = Out(MIME.FileName);


    Some online info at:
    BizTalk Gurus: Email Attachment's filename
    http://www.biztalkgurus.com/forums/p/1702/2759.aspx#2759

    Friday, December 12, 2008 7:01 PM
  • Hi

    i am facing problem with pop3 adapter ,

    i am not getting MIME.filename in my orchastration...

    here i am not understand this path pls can explain me.( http://schemas.microsoft.com/BizTalk/2003/mime-properties)

    regards
    vittalaranga
    Monday, May 18, 2009 12:29 PM
  • has Anybody ever FOUND out the solution the PROBLEM of extracting Attachment when Email Body is BLANK??

     

    I'm Extracting Attachments in the loop in my orch and it works PERFECTLY when sender sends some text in the email body.

    My setting on Receive Location using POP3 Adapter is this

    Body Part Index is set to 0 and the Body Part Content Type is blank

    because i receive any count of attachment Invoices from any sender in the world.

    2nd part of the problem is that..

    in Many cases i get the attachment name right [original] but in most cases its a GUIID.. but attachment does get saved loosing the original name.

    since Im using this so this is how iM getting name of the attachment....

     

    varXmessage= msgEmailIn;  [varXmessage  is variable of type Microsoft.XLANGs.BaseTypes.XLANGMessage]

     

    varCount=varXmessage.Count;  [This is getting the PART count on the incoming EMAIL.]

    This GOES DOWN in the LOOP

         MsgPart  is a variable of type Microsoft.XLANGs.BaseTypes.XLANGPart

         MsgPart = varXmessage[StartLoop];

         varAttachedFileName = MsgPart.Name.ToString();

    URGENT ANY HELP is appreciated... I'm going crazy on this problem for weeks.

    Thursday, January 20, 2011 4:33 PM
  • I recently wrote this blog post: http://blog.vertica.dk/post/Processing-multiple-email-attachments-with-Biztalk-Server-2009-using-POP3-adapter-and-orchestration.aspx which should describe the solution to your problem.

    Basically, onyour msgPart you need to call GetPartProperty with type MIME.FileName(located in GlobalPropertySchemas.dll). Let me know if you have any questions.

     

     

    Friday, January 21, 2011 8:32 AM
  • TBerg,

    I have 2 Email Projects developed in past based on business needs.

     

    1. Just extract the body of the email ignoring whatever attachments. that was easy and was done with a Custom Pipeline and nothing special.

    2. Allow & Extract only 1 Attachment. this was developed using Logic SIMILAR to yours 

    varXmessage= msgEmailIn;

    varCount=varXmessage.Count;

    msgEmailIn being a MultiPart message with 2 Parts 1 Body 1 Attachment

    msgEmailOut = msgEmailIn.msgPartAttachment;

    varAttachedFileName = msgEmailIn.msgPartAttachment(MIME.FileName);

    msgEmailOut(FILE.ReceivedFileName)=varAttachedFileName;

    i tried to expand this approach when i received 3rd project in whcih i had to extract multi attachment  and i went a difft approach because it didnt work for me...

    i will dig in again and try to see  if i can do that.... do you have plan to shar your solution on your blog?

     

    Tuesday, January 25, 2011 9:48 PM
  • @BizTalk,

    I dont plan to share the solution but I'll do my best to answer any questions you may have.

    Wednesday, January 26, 2011 3:03 PM
  • Hello Kent,

    I am able to retrieve the attachments using pop3 adaptor as suggested by you but can not preserve the original attachment file name.

    However, i have also put macro %SourceFileName% at my send port. It is giving me GUIID as the name of attachment file.

    Saturday, January 29, 2011 3:11 AM
  • Any help will be appreciated.

    Thanks

    Saturday, January 29, 2011 3:12 AM
  • To my knowledge the %SourceFileName% only takes the ReceivedFileName property. You'll need to promote the attachment file name to the receivedfilename property to use %SourceFileName%. You could possibly also use a dynamic send port in an orchestration and set the filename from the mime.filename.

    Saturday, January 29, 2011 1:04 PM
  • Seems you have the same issue as we had.

    Try using MIME.PartContentTypeSecondaryHeaderValue

    FYI

    http://biztalkconnect.blogspot.com/2011/04/mimefilename-blank.html


    Regards, NISHIL. MCT,MCTS BizTalk Server,MS BI. Http://www.KnishTech.com Http://www.BiztalkForums.com .Chat with Nishil now! NishilJain @ hotmail,gmail,Yahoo
    Thursday, April 21, 2011 9:44 PM