BizTalk – Send Dynamic File from Orchestration

Suppose you have StartMsg and you want to send it to a dynamic disk path. I would build another new message called StartMsgDyn. If you want to use a GUID to make the file unique, as I do in my example code below, then create an orchestration variable called “GuidVar” of type of .NET Class System.Guid. The logical port name in my example is “ArchiveDynPort”, and you have to flag it as “Dynamic” instead of “Specify Later”.
(I also use string variables: Path, Filename, DynFileAddress to make the code more clear, but you don’t necessarily need those.)

You can put the following in a message construct statement, then add a normal send shape associated with the message you construct (StartMsgDyn in my example).

StartMsgDyn = StartMsg;            // copy the original message 
StartMsgDyn (*) = StartMsg (*);    // copy promoted fields from the original message (if desired) 

//Set port "DynFILESendPort" properties
StartMsgDyn(FILE.CopyMode) =  1;                      //  0=Append, 1=Create New, 2=Overwrite
StartMsgDyn(FILE.UseTempFileOnWrite) =  false;

// Use a GUID or Date/Time (down to milliseconds) to make sure filename is unique. 
GuidVar = System.Guid.NewGuid();
Path = @"C:\BizTalk\Project\archive\";    
Filename =  @"Dyn_" + GuidVar.ToString() + ".txt"

DynFileAddress = "file://" +
                 Path + Filename

ArchiveDynPort(Microsoft.XLANGs.BaseTypes.Address)= DynFileAddress;
ArchiveDynPort(Microsoft.XLANGs.BaseTypes.TransportType) = "FILE";

I made a big mistake and put DynFileAddress = “@file://” etc…
This caused the error: “The FILE send adapter cannot open file @file:c:\:\BizTalk\Project\archive\guid.txt for writing. Details: The filename, directory name, or volume label syntax is incorrect.” That is because for whatever reason, I put the @ sign in front of “file://”. Maybe I meant to put the @ sign before the double quotes to avoid escape characters originally.

You can also get this error if you have any characters not allows in a filename, such as a colon, percent sign, comma, etc…
To verify if that is the issue, you can open NotePad or NotePad++, and do file save, then paste in the name found in your error. Then see if NotePad as able to save the file with the given name.

Leave a Reply

Recent Posts




All Rights Reserved Theme by 404 THEME.