BizTalk Scenario: Reading a file from an orchestration
Introduction
Recently a couple of folks asked me how to read a file from an orchestration that is activated by an HTTP receive port. This can be a bit confusing at first, because when one thinks reading a file in BizTalk they often think about a FILE Receive Location. On this scenario we are NOT using a FILE receive location to read the file, as the Receive Shape that activates the orchestration is totally unrelated to the file in question.
The solution is simple and a bit obvious, but because of the way we think about a file when we work with BizTalk, it becomes obscure.
Scenario
Your have a requirement to read content from a file, either XML or otherwise, during the execution of an orchestration. The orchestration is initialized by a Receive Shape unrelated to the file, and the file is not to be "picked up" when read, remaining at its location after being read. It contains static contents, or contents that are provided by a different process at a unrelated time.
Implementation
The way to read the file is to create a variable in the orchestration, say "theXmlContent" and read the file directly into the variable placing code like the snippet below into an Expression Shape:
theXmlContent = System.IO.File.ReadAllText(@"C:\FILE\ContentFile.XML");
Here are a few things to note:
- On the code snippet above an XML file is being read into the "theXmlContent" string variable, but this content could be of anytype.
- The file location and name is static in the code snippet for the sake of clarity. You will want it to be configurable.
- The user running the host instance bound to your orchestration will need to have read access to the file.
Conclusion
With this simplistic approach you can use the string variable as desired without having to deal with dynamic receive ports or other more complicated techniques.
See Also
Another important place to find an extensive amount of BizTalk related articles is the TechNet Wiki itself. The best entry point is BizTalk Server Resources on the TechNet Wiki.