none
Access the filename in biztalk map RRS feed

  • Question

  • Hi All,

    I want to access the context data filename in map and I need to map that filename to one field in destination schema.

    Note: I am not using orchestration here.

    Any suggestion please.

    Thanks.

    Friday, January 1, 2016 7:20 PM

Answers

  • Hi Ram,

    If you are not using Orchestration in place then you need  a functoid that will read the filename from the context of the message.

    You can find the Context accessor functiod at http://contextaccessor.codeplex.com/

    Another you can find at http://dl.dropbox.com/u/18955972/ContextAccessorSourceCode.zip

    Easy way would be to use Orchestration and access the message context property there.

    Thanks

    Abhishek


    If this answers your question please mark it accordingly. If this post is helpful, please vote as helpful by clicking the upward arrow mark next to my reply

    • Marked as answer by BizTalk1234 Sunday, January 10, 2016 10:50 AM
    Sunday, January 3, 2016 7:03 AM
  • ...

    The message part data does not contain at least one of the nodes specified by the XPath expression (listed below) that corresponds to the distinguished field.

    ...

    The node represented by a Distinguished Field must exist in the Xml Document for it to be used.  It is not automatically created.

    In the Map, set the file name field to any temp value, such as "MAPNAME", then, the Distinguished Field will work and overwrite that value.

    • Marked as answer by BizTalk1234 Sunday, January 3, 2016 5:12 PM
    • Unmarked as answer by BizTalk1234 Tuesday, January 5, 2016 7:59 PM
    • Marked as answer by BizTalk1234 Saturday, January 9, 2016 6:14 PM
    • Unmarked as answer by BizTalk1234 Sunday, January 10, 2016 10:30 AM
    • Marked as answer by BizTalk1234 Sunday, January 10, 2016 10:30 AM
    Sunday, January 3, 2016 3:43 PM
    Moderator
  • Hi Abhishek,

    I am using the Context accessor functiod in My map and I am getting the filename full path,I need only the filename without extension please tell me what I need to modify in execute method in order to come only filename.

      internal static IBaseMessageContext context;

            public IBaseMessage Execute(IPipelineContext pContext, IBaseMessage pInMsg)
            {
                context = pInMsg.Context;
                return pInMsg;
            }

    Thanks.

    Hi Ram,

    You can use of the GetFileNameWithoutExtension method, Code should be like below,

    if (!string.IsNullOrEmpty(archiveFileName)) { fileNameWithoutExtension = Path.GetFileNameWithoutExtension(archiveFileName);

    }


    Thanks,

    If my reply is helpful please mark as Answer or vote as Helpful.

    My blog | Twitter | LinkedIn

    This post is my own opinion and does not necessarily reflect the opinion or view of Microsoft, its employees, or other MVPs.

    • Marked as answer by BizTalk1234 Sunday, January 10, 2016 11:21 AM
    Sunday, January 10, 2016 10:54 AM
    Moderator

All replies

  • You have three practical options:

    1. Set the value on the output message through a Distinguished Field in an Orchestration.  There is nothing wrong with using an Orchestration.
    2. Use a Context Accessor Functoid such as the one found here: https://adifferentkindofquery.wordpress.com/2013/04/08/improved-context-accessor-functoid/
    3. Use Property Demotion in the Send Pipeline.

    Friday, January 1, 2016 11:31 PM
    Moderator
  • Hi Ram,

    If you are not using Orchestration in place then you need  a functoid that will read the filename from the context of the message.

    You can find the Context accessor functiod at http://contextaccessor.codeplex.com/

    Another you can find at http://dl.dropbox.com/u/18955972/ContextAccessorSourceCode.zip

    Easy way would be to use Orchestration and access the message context property there.

    Thanks

    Abhishek


    If this answers your question please mark it accordingly. If this post is helpful, please vote as helpful by clicking the upward arrow mark next to my reply

    • Marked as answer by BizTalk1234 Sunday, January 10, 2016 10:50 AM
    Sunday, January 3, 2016 7:03 AM
  • Hi Ram,

    Thank you for posting in MSDN forum.

    You can use Context Accessor functoid in Map available at codeplex.

    You can do it in orchestration by inserting Message Assignment shape after Transform shape in the same Construct Message shape.

    Inside Message Assignment you can assign FILE.ReceivedFileName to the distinguished fields in destination schema.

    So in you map you do not need to map this field.

    You need to assign them in your orchestration

    I hope this will help.

    Please refer below article for reference,

    Fetching custom context properties in Maps

    Thanks,

    If my reply is helpful please mark as Answer or vote as Helpful.

    My blog | Twitter | LinkedIn

    This post is my own opinion and does not necessarily reflect the opinion or view of Microsoft, its employees, or other MVPs.

    • Marked as answer by BizTalk1234 Sunday, January 3, 2016 5:13 PM
    • Unmarked as answer by BizTalk1234 Tuesday, January 5, 2016 7:59 PM
    Sunday, January 3, 2016 9:30 AM
    Moderator
  • Hi Kamlesh,

    I have promoted the destination schema field to distinguished field and I have applied below expressing in message assaignment shape in same construct shape after transform shape.I am getting below error

    outmsg.name=inmsg(FILE.ReceivedFileName);

    I have not mapped anything in transform shape and I applied above expression in message assaignment shape.

    xlang/s engine event log entry: Uncaught exception (see the 'inner exception'
    below) has suspended an instance of service
    'ReadingFileNameInBiztalkorch.BizTalk_Orchestration1(c7574132-6153-03ab-bdfa-6001c38d65d9)'.
    The service instance will remain suspended until administratively resumed or
    terminated. If resumed the instance will continue from its last persisted state
    and may re-throw the same unexpected exception. InstanceId:
    1cabeb4e-ae76-44f7-9f9e-5f776dfb4be3 Shape name: ConstructMessage_1 ShapeId:
    2098a5d8-49da-4e98-bb57-c438fae1719d Exception thrown from: segment 1, progress
    6 Inner exception: A failure occurred while evaluating the distinguished field
    name against the message part data. The message part data does not contain at
    least one of the nodes specified by the XPath expression (listed below) that
    corresponds to the distinguished field. The cause for this error may be that the
    message part data has not been initialized or that the message part data does
    not conform to the message part schema. Ensure that the message part data is
    initialized correctly. XPath expression: /*[local-name()='Destination' and
    namespace-uri()='http://ReadingFileNameInBiztalkorch.Schema2']/*[local-name()='name'
    and namespace-uri()=''] Exception type: XPathUpdateException Source:
    Microsoft.XLANGs.Engine Target Site: Void SetDistinguishedField(System.String,
    System.Object) The following is a stack trace that identifies the location where
    the exception occured at
    Microsoft.XLANGs.Core.XSDPart.SetDistinguishedField(String dottedPath, Object
    val) at
    ReadingFileNameInBiztalkorch.BizTalk_Orchestration1.segment1(StopConditions
    stopOn) at Microsoft.XLANGs.Core.SegmentScheduler.RunASegment(Segment s,
    StopConditions stopCond, Exception& exp)

    Sunday, January 3, 2016 1:56 PM
  • Inner exception: A failure occurred while evaluating the distinguished field 
    name against the message part data. The message part data does not contain at 
    least one of the nodes specified by the XPath expression (listed below) that 
    corresponds to the distinguished field. The cause for this error may be that the 
    message part data has not been initialized or that the message part data does 
    not conform to the message part schema. Ensure that the message part data is 
    initialized correctly.

    Above error clearly says message part data has not been initialized and because of this your are getting above error.

    I would suggest please have a look into below article created by Maheshkumar Tiwari,

    The cause for this error may be that the message part data has not been initialized

    Thanks,

    If my reply is helpful please mark as Answer or vote as Helpful.

    My blog | Twitter | LinkedIn

    This post is my own opinion and does not necessarily reflect the opinion or view of Microsoft, its employees, or other MVPs.

    Sunday, January 3, 2016 3:17 PM
    Moderator
  • Ram, Please have a look into below similar thread for some reference,

    A failure occurred while evaluating the distinguished field

    Thanks,

    If my reply is helpful please mark as Answer or vote as Helpful.

    My blog | Twitter | LinkedIn

    This post is my own opinion and does not necessarily reflect the opinion or view of Microsoft, its employees, or other MVPs.

    Sunday, January 3, 2016 3:19 PM
    Moderator
  • ...

    The message part data does not contain at least one of the nodes specified by the XPath expression (listed below) that corresponds to the distinguished field.

    ...

    The node represented by a Distinguished Field must exist in the Xml Document for it to be used.  It is not automatically created.

    In the Map, set the file name field to any temp value, such as "MAPNAME", then, the Distinguished Field will work and overwrite that value.

    • Marked as answer by BizTalk1234 Sunday, January 3, 2016 5:12 PM
    • Unmarked as answer by BizTalk1234 Tuesday, January 5, 2016 7:59 PM
    • Marked as answer by BizTalk1234 Saturday, January 9, 2016 6:14 PM
    • Unmarked as answer by BizTalk1234 Sunday, January 10, 2016 10:30 AM
    • Marked as answer by BizTalk1234 Sunday, January 10, 2016 10:30 AM
    Sunday, January 3, 2016 3:43 PM
    Moderator
  • Hi Jhon,

    How to access the context filename in map?

    I have read the other post they said need to use context accesor functiod.

     but can we use third party functiods in our project actually need licence to use right?

    is there any other way to access the filename in map without context accessor functiod?

    Thanks.

    Tuesday, January 5, 2016 7:59 PM
  • Hi Jhon,

    How to access the context filename in map?

    I have read the other post they said need to use context accesor functiod.

     but can we use third party functiods in our project actually need licence to use right?

    is there any other way to access the filename in map without context accessor functiod?

    Thanks.

    You can write a custom pipeline to read the filename property and Map it to any element.

    Please have a look into below related thread and some good article for reference,

    In custom Pipeline naming the filename

    How to get the source file name in a pipeline component

    Get the name of received file in Biztalk


    Thanks,

    If my reply is helpful please mark as Answer or vote as Helpful.

    My blog | Twitter | LinkedIn

    This post is my own opinion and does not necessarily reflect the opinion or view of Microsoft, its employees, or other MVPs.

    Tuesday, January 5, 2016 8:11 PM
    Moderator
  • What was wrong with the Distinguished Field solution?
    Tuesday, January 5, 2016 8:33 PM
    Moderator
  • Try  This

    Exp_GetFileName :

    strFilenamewithPath=MsgIn(FILE.ReceivedFileName);

    StrFileName=System.IO.Path.GetFileName(strFilenamewithPath);

    Tra_FileName:

    MSGAssignFileName:

    GetFileName.Filename=StrFileName;


    • Edited by vittalaranga Wednesday, January 6, 2016 8:49 AM
    • Marked as answer by BizTalk1234 Saturday, January 9, 2016 6:14 PM
    • Unmarked as answer by BizTalk1234 Sunday, January 10, 2016 10:30 AM
    Wednesday, January 6, 2016 7:39 AM
  • Hi Abhishek,

    I am using the Context accessor functiod in My map and I am getting the filename full path,I need only the filename without extension please tell me what I need to modify in execute method in order to come only filename.

      internal static IBaseMessageContext context;

            public IBaseMessage Execute(IPipelineContext pContext, IBaseMessage pInMsg)
            {
                context = pInMsg.Context;
                return pInMsg;
            }

    Thanks.

    Sunday, January 10, 2016 10:30 AM
  • Hi Abhishek,

    I am using the Context accessor functiod in My map and I am getting the filename full path,I need only the filename without extension please tell me what I need to modify in execute method in order to come only filename.

      internal static IBaseMessageContext context;

            public IBaseMessage Execute(IPipelineContext pContext, IBaseMessage pInMsg)
            {
                context = pInMsg.Context;
                return pInMsg;
            }

    Thanks.

    Hi Ram,

    You can use of the GetFileNameWithoutExtension method, Code should be like below,

    if (!string.IsNullOrEmpty(archiveFileName)) { fileNameWithoutExtension = Path.GetFileNameWithoutExtension(archiveFileName);

    }


    Thanks,

    If my reply is helpful please mark as Answer or vote as Helpful.

    My blog | Twitter | LinkedIn

    This post is my own opinion and does not necessarily reflect the opinion or view of Microsoft, its employees, or other MVPs.

    • Marked as answer by BizTalk1234 Sunday, January 10, 2016 11:21 AM
    Sunday, January 10, 2016 10:54 AM
    Moderator
  • Hi Kamplesh,

    Thanks for your quick replay.

    Sunday, January 10, 2016 11:21 AM
  • Hi Kamlesh,

    Is there any property promotions is happens in send pipeline ?

    I am promoting one field in canonical schema and I assigned received filename t that field.

    If I place the component in send pipeline or receive pipeline the receivedFilename is not populating with the field.any suggestions?

    Thanks,


    • Edited by BizTalk1234 Saturday, January 16, 2016 7:33 PM
    Saturday, January 16, 2016 7:33 PM
  • Since this is a different question, you should start a new thread.
    Saturday, January 16, 2016 9:02 PM
    Moderator