Destination File Name in an Email body

Home Page Forums BizTalk 2004 – BizTalk 2010 Destination File Name in an Email body

Viewing 1 reply thread
  • Author
    Posts
    • #24861

      Hi

      Nice forum here.

      I am a newbie in BizTalk and have a question about The BizTalk Expression Editor.
      How I can add the destination file name as a variable in the email body? (See script below)

      That the szenario is:

      1. I receive an XML file “example.xml” on a receive port (looks for xml files in a folder “in”)
      2. This “message” works through a scheme mapping and
      3. It will be saved as a XML file in a folder “out”
      4. After that the message walks through a XML2HTML pipeline to transform it into an HTML file.
      and will be saved in another folder “web” via the sendPort.
      5. After that an email will be generated.

      These steps are working well.

      But now I want to add the filename of the HTML file in the email body and I don’t know how I can access to that variable.

      Here are some screens and scripts about that.

      Script “Create HTML Code”:

      SendEmail(Microsoft.XLANGs.BaseTypes.Address) = “mailto:”+ReceiveMessage(RonnysProjekt.PropertySchema.Email);

      SendMessage2 = ReceiveMessage;
      SendMessage2(SMTP.EmailBodyTextCharset) = “UTF-8”;
      SendMessage2(SMTP.Subject) = “Testmail mit URL”;
      SendMessage2(SMTP.EmailBodyText) = “http://biztalkdev.local/biztalk/” + System.Convert.ToString(???)
      ;

      What should be written instead of the questionmarks

      Thanky for your help!

    • #24863

      Hi,

       

         It all depends on how your XML2HTML pipeline (in step 4) constructs the filename of your HTML output file. Is it dynamic? Static? Does the pipeline itself control the way the filename is set? Or is this something that you can control through custom modification and coding?

       

         Daniel.

       

      • #24885

        Hi Daniel

        Sorry for late answer but we had a bank holiday in Germany yesterday.
        Are you a German too?

        Anyway, please find below the code of the XML2HTMLSendPipeline.btb I couldn’t find a path or a name there the file will be saved as html. Can you?

        Do you need the C# script too?

        Many thanks for your help.

        —————-
        <?xml version=”1.0″ encoding=”utf-16″?>
        <Document xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221;
        xmlns:xsd=”http://www.w3.org/2001/XMLSchema&#8221;
        PolicyFilePath=”BTSTransmitPolicy.xml” MajorVersion=”1″
        MinorVersion=”0″>
          <Description />
          <Stages>
            <Stage CategoryId=”9d0e4101-4cce-4536-83fa-4a5040674ad6″>
              <Components />
            </Stage>
            <Stage CategoryId=”9d0e4107-4cce-4536-83fa-4a5040674ad6″>
              <Components>
                <Component>
                  <Name>Microsoft.BizTalk.Component.XmlAsmComp</Name>
                  <ComponentName>XML assembler</ComponentName>
                  <Description>XML assembler component.</Description>
                  <Version>1.0</Version>
                  <Properties>
                    <Property Name=”EnvelopeDocSpecNames”>
                      <Value xsi:type=”xsd:string” />
                    </Property>
                    <Property Name=”EnvelopeSpecTargetNamespaces”>
                      <Value xsi:type=”xsd:string” />
                    </Property>
                    <Property Name=”DocumentSpecNames”>
                      <Value xsi:type=”xsd:string” />
                    </Property>
                    <Property Name=”DocumentSpecTargetNamespaces”>
                      <Value xsi:type=”xsd:string” />
                    </Property>
                    <Property Name=”XmlAsmProcessingInstructions” />
                    <Property Name=”ProcessingInstructionsOptions”>
                      <Value xsi:type=”xsd:int”>0</Value>
                    </Property>
                    <Property Name=”ProcessingInstructionsScope”>
                      <Value xsi:type=”xsd:int”>0</Value>
                    </Property>
                    <Property Name=”AddXmlDeclaration”>
                      <Value xsi:type=”xsd:boolean”>true</Value>
                    </Property>
                    <Property Name=”TargetCharset”>
                      <Value xsi:type=”xsd:string” />
                    </Property>
                    <Property Name=”TargetCodePage”>
                      <Value xsi:type=”xsd:int”>0</Value>
                    </Property>
                    <Property Name=”PreserveBom”>
                      <Value xsi:type=”xsd:boolean”>true</Value>
                    </Property>
                    <Property Name=”HiddenProperties”>
                      <Value
        xsi:type=”xsd:string”>EnvelopeSpecTargetNamespaces,DocumentSpecTargetNam
        espaces,TargetCodePage</Value>
                    </Property>
                  </Properties>
                  <CachedDisplayName>XML assembler</CachedDisplayName>
                  <CachedIsManaged>true</CachedIsManaged>
                </Component>
              </Components>
            </Stage>
            <Stage CategoryId=”9d0e4108-4cce-4536-83fa-4a5040674ad6″>
              <Components>
                <Component>
         
        <Name>Microsoft.BizTalk.SDKSamples.Pipelines.XslTransformComponent.XslTr
        ansformer</Name>
                  <ComponentName>XSL Transform Component</ComponentName>
                  <Description>XSL Transform Pipeline Component</Description>
                  <Version>1.0</Version>
                  <Properties>
                    <Property Name=”XsltFilePath”>
                      <Value xsi:type=”xsd:string”>E:\BizTalk\Computerlinks
        Orchestrations\RONNY\RonnysProjekt\transform.xsl</Value>
                    </Property>
                  </Properties>
                  <CachedDisplayName>XSL Transform Component</CachedDisplayName>
                  <CachedIsManaged>true</CachedIsManaged>
                </Component>
              </Components>
            </Stage>
          </Stages>
        </Document>
        —————-

         

        • #24890

          Hi,

           

             I hope you enjoyed the day off… I am not German, but I’ve enjoyed visiting Germany in the past. 🙂

           

             The XML code you pasted above does not tell how and where the HTML file is output, so can you paste the C# script?

           

             Daniel.

           

          • #24905

            Hi Daniel

            A mlittle bit late but I had some days off…

            Please find the code below…

            //———————————————————————
            // Datei:           XslTransformer.cs
            // Beschreibung:    Eine Pipeline, welche mittels eines XSL Dokumentes
            //                  eingehende XML nachrichten (messages) in ein HTML Dokumnet konvertiert
            // Beispiel:        Erstellt aus Vorlage aus dem SDK von MS BizTalk Server 2006
            //———————————————————————

            using System;
            using System.IO;
            using System.Xml;
            using System.Xml.Xsl;
            using System.ComponentModel;
            using System.Collections;
            using Microsoft.BizTalk.Message.Interop;
            using Microsoft.BizTalk.Component.Interop;
            using Microsoft.Win32;

            namespace Microsoft.BizTalk.SDKSamples.Pipelines.XslTransformComponent
            {
                /// Implements a pipeline component that applies Xsl Transformations to XML messages
                /// </summary>
                /// <remarks>
                /// XslTransformer class implements pipeline components that can be used in send pipelines
                /// to convert XML messages to HTML format for sending using SMTP transport. Component can
                /// be placed only in Encoding stage of send pipeline
                /// </remarks>
                [ComponentCategory(CategoryTypes.CATID_PipelineComponent)]
                [ComponentCategory(CategoryTypes.CATID_Encoder)]
                [System.Runtime.InteropServices.Guid(“FA7F9C55-6E8E-4855-8DAC-FA1BC8A499E2”)]
                public class XslTransformer        : Microsoft.BizTalk.Component.Interop.IBaseComponent,
                                                  Microsoft.BizTalk.Component.Interop.IComponent,
                                                  Microsoft.BizTalk.Component.Interop.IPersistPropertyBag,
                                                  Microsoft.BizTalk.Component.Interop.IComponentUI
                {   
                   
                    private string xsltPath    = null;
                   
                    /// <summary>
                    /// Location of Xsl transform file.
                    /// </summary>
                    public string XsltFilePath
                    {
                        get {    return xsltPath;}
                        set {    xsltPath = value;}
                    }

                   
                    #region IBaseComponent
                   
                    /// <summary>
                    /// Name of the component.
                    /// </summary>
                    [Browsable(false)]
                    public string Name
                    {
                        get {    return “XSL Transform Component”;    }
                    }
                   
                    /// <summary>
                    /// Version of the component.
                    /// </summary>
                    [Browsable(false)]
                    public string Version
                    {
                        get    {    return “1.0”;    }
                    }
                   
                    /// <summary>
                    /// Description of the component.
                    /// </summary>
                    [Browsable(false)]
                    public string Description
                    {
                        get    {    return “XSL Transform Pipeline Component”;    }
                    }
               
                    #endregion
                   
                    #region IComponent

                    /// <summary>
                    /// Implements IComponent.Execute method.
                    /// </summary>
                    /// <param name=”pc”>Pipeline context</param>
                    /// <param name=”inmsg”>Input message.</param>
                    /// <returns>Converted to HTML input message.</returns>
                    /// <remarks>
                    /// IComponent.Execute method is used to convert XML messages
                    /// to HTML messages using provided Xslt file.
                    /// It also sets the content type of the message part to be “text/html”
                    /// which is necessary for client mail applications to correctly render
                    /// the message
                    /// </remarks>
                    public IBaseMessage Execute(IPipelineContext pc, IBaseMessage inmsg)
                    {
                        inmsg.BodyPart.Data = TransformMessage(inmsg.BodyPart.Data);
                        inmsg.BodyPart.ContentType = “text/html”;
                        return inmsg;
                    }
                    #endregion

                    #region Helper function
                    /// <summary>
                    /// Transforms XML message in input stream to HTML message
                    /// </summary>
                    /// <param name=”stm”>Stream with input XML message</param>
                    /// <returns>Stream with output HTML message</returns>
                    private Stream TransformMessage(Stream stm)
                    {
                        MemoryStream ms = null;
                        string validXsltPath = null;
                       
                        try
                        {
                            // Get the full path to the Xslt file
                            validXsltPath = GetValidXsltPath(xsltPath);
                           
                            // Load transform
                            XslTransform transform = new XslTransform();
                            transform.Load(validXsltPath);
                           
                            //Load Xml stream in XmlDocument.
                            XmlDocument doc = new XmlDocument();
                            doc.Load(stm);
                           
                            //Create memory stream to hold transformed data.
                            ms = new MemoryStream();
                           
                            //Preform transform
                            transform.Transform(doc, null, ms, null);
                            ms.Seek(0, SeekOrigin.Begin);
                        }
                        catch(Exception e)
                        {
                            System.Diagnostics.Trace.WriteLine(e.Message);
                            System.Diagnostics.Trace.WriteLine(e.StackTrace);
                            throw e;
                        }

                        return ms;
                    }

                    /// <summary>
                    /// Liefert den Pfad zur Xslt file
                    /// Wenn kein Pfad in den Eigenschaften der Pipeline angegeben ist,
                    /// wird in der Registry gesucht
                    /// Hier ist der Pfad in den Properties der Pipeline eingetragen
                    /// –> E:\BizTalk\Computerlinks Orchestrations\RONNY\XslTransformComponent\XslTransform\bin\Debug\XslTransform.dll
                    /// </summary>
                    /// <param name=”path”>Pfad des Users aus dem Pipeline Designer</param>
                    /// <returns>Gibt den vollständigen Pfad der XSLT Datei</returns>
                    private string GetValidXsltPath(string path)
                    {
                        string validPath = path;

                        if (!System.IO.File.Exists(path))
                        {
                            RegistryKey rk = Registry.LocalMachine.OpenSubKey(@”SOFTWARE\Microsoft\BizTalk Server\3.0″);
                            string InstallPath = string.Empty;
                           
                            if (null != rk)
                                InstallPath = (String)rk.GetValue(“InstallPath”);      
                           
                            validPath = InstallPath + @”Pipeline Components\” + path;
                           
                            if (!System.IO.File.Exists(validPath))
                            {
                                throw new ArgumentException(“The XSL transformation file ” + path + ” can not be found”);
                            }
                        }   

                        return validPath;
                    }

                    #endregion   
                   

                    #region IPersistPropertyBag
               
                    /// <summary>
                    /// Gets class ID of component for usage from unmanaged code.
                    /// </summary>
                    /// <param name=”classid”>Class ID of the component.</param>
                    public void GetClassID(out Guid classid)
                    {
                        classid = new System.Guid(“FA7F9C55-6E8E-4855-8DAC-FA1BC8A499E2”);
                    }
                   
                    /// <summary>
                    /// Not implemented.
                    /// </summary>
                    public void InitNew()
                    {
                    }
                   
                    public void Load(Microsoft.BizTalk.Component.Interop.IPropertyBag pb, Int32 errlog)
                    {
                        string val = (string)ReadPropertyBag(pb, “XsltFilePath”);
                        if (val != null) xsltPath = val;
                    }
                   
                    /// <summary>
                    /// Saves the current component configuration into the property bag.
                    /// </summary>
                    /// <param name=”pb”>Configuration property bag.</param>
                    /// <param name=”fClearDirty”>Not used.</param>
                    /// <param name=”fSaveAllProperties”>Not used.</param>
                    public void Save(Microsoft.BizTalk.Component.Interop.IPropertyBag pb, Boolean fClearDirty, Boolean fSaveAllProperties)
                    {
                        object val = (object)xsltPath;
                        WritePropertyBag(pb, “XsltFilePath”, val);           
                    }

                    /// <summary>
                    /// Reads property value from property bag.
                    /// </summary>
                    /// <param name=”pb”>Property bag.</param>
                    /// <param name=”propName”>Name of property.</param>
                    /// <returns>Value of the property.</returns>
                    private static object ReadPropertyBag(Microsoft.BizTalk.Component.Interop.IPropertyBag pb, string propName)
                    {
                        object val = null;
                        try
                        {
                            pb.Read(propName,out val,0);
                        }

                        catch(System.ArgumentException)
                        {
                            return val;
                        }
                        catch(Exception ex)
                        {
                            throw new ApplicationException( ex.Message);
                        }
                        return val;
                    }

                    private static void WritePropertyBag(Microsoft.BizTalk.Component.Interop.IPropertyBag pb, string propName, object val)
                    {
                        try
                        {
                            pb.Write(propName, ref val);
                        }
                        catch(Exception ex)
                        {
                            throw new ApplicationException( ex.Message);
                        }
                    }
                
                    #endregion

                    #region IComponentUI
                    /// <summary>
                    /// Component icon to use in BizTalk Editor.
                    /// </summary>
                    [Browsable(false)]
                    public IntPtr Icon
                    {
                        get    {    return IntPtr.Zero;    }
                    }

                    /// <summary>
                    /// The Validate method is called by the BizTalk Editor during the build
                    /// of a BizTalk project.
                    /// </summary>
                    /// <param name=”obj”>Project system.</param>
                    /// <returns>
                    /// A list of error and/or warning messages encounter during validation
                    /// of this component.
                    /// </returns>
                    public IEnumerator Validate(object projectSystem)
                    {
                        if (projectSystem==null)
                            throw new System.ArgumentNullException(“No project system”);

                        IEnumerator enumerator = null;
                        ArrayList   strList  = new ArrayList();

                        try
                        {
                            GetValidXsltPath(xsltPath);
                        }
                        catch(Exception e)
                        {
                            strList.Add(e.Message);
                            enumerator = strList.GetEnumerator();
                        }

                        return enumerator;
                    }

                    #endregion

               
                }
            }

             

            Thanks for your help

            • #24907

              Hi,

               

                 In your application, do you have a place where the XSL Transform component is invoked (through the public IBaseMessage Execute method), whether it’s in or outside of BizTalk? Where that method is called is the place you should look at to see how the HTML filename is generated (and that provides you with a way to return that filename value to your BizTalk orchestration).

               

                 Daniel.

               

              • #24908

                On my SendPort there will the File saved as %MEssageID%.html but how can I use that in the Biztalk Expression Editor?

                I tried:

                SendMessage2 = ReceiveMessage;
                SendMessage2(SMTP.EmailBodyTextCharset) = “UTF-8”;
                SendMessage2(SMTP.Subject) = “Testmail mit URL”;
                SendMessage2(SMTP.EmailBodyText) = “http://localhost/biztalk/&#8221; +
                System.Convert.ToString(ReceiveMessage(BTS.MessageID)) + “/” +
                System.Convert.ToString(SendMessage(BTS.InAppStreamGUID));

                But both are not the correct one.

                 

                • #24910

                  Hi,

                   

                    One suggestion I have is:

                  1) Make your HTML send port dynamic (I assume it’s the SaveHTML port in the Port Surface in your diagram above), and use the FILE.ReceivedFileName context property of your initial message (assuming it’s ReceiveMessage) as part of your destination filename (make sure to parse out the “.xml” extension).

                  2) In an Expression shape before your HTML send port, you can do the following assignment (to dynamically configure your send port):

                  saveHTML(Microsoft.XLANGs.BaseTypes.Address) = “FILE://YourPath/YourFileName.html”;

                     Where YourFileName is obtained from step 1.

                     I hope this is a workable solution for you.

                     Daniel.

                  • #24911

                    OK. That sounds like a solution I can work with.
                    But now I will try to do that.

                    I will let you know then! 🙂

                    Thank you…

                    • #25117

                      Hi,

                       

                         Did you ever get that solution that I suggested to work? Let me know how it turned out for you…

                       

                         Daniel.

                       

Viewing 1 reply thread
  • The forum ‘BizTalk 2004 – BizTalk 2010’ is closed to new topics and replies.