BizTalk 2016 orchestration - biztalk

I need to recognize a file type and make a decision in a decision shape according to a file type.
I will receive 2 types of file: csv and JPG. So if it is CSV - send here, if JPG - send another way. So my question is how to recognize file type in decision shape in a orchestration?

You can get the filename from the context property called BTS.ReceivedFileName on the message.
FileName = InputMessage(BTS.ReceivedFileName);
Then you will probably need to make a call to a C# method Path.GetExtension
extension = Path.GetExtension(FileName);
Then you can have a decision shape based on the extension

Related

Can i get access over file in FileWriter Filter of Directshow

I have read the FileWriter Filter :
" The File Writer filter can be used to write files to disc regardless of format. The filter simply writes to disc whatever it receives on its input pin, so it must be connected upstream to a multiplexer that can format the file correctly. You can create a new output file with the File Writer or specify an existing file; if the file already exists, it will be completely overwritten with the new data. "
So my question is :
I am using the FileWriter filter for writing my audio stream into the disc. Before writing the file in the disc i want to access that file , so can it be possible or should i make my own custom filter.
File writer filter does not not provide you with options to change file sharing mode while the file is being written to. Additionally, in most cases your accessing the file before it is finalized makes no sense: the files are rarely written incrementally, file finalization changes data in the middle of the file and your accessing data before the file is closed might get you bad/incomplete stream.
Roman R is right. Writers are for writing. If you need transform data - write your own Transform filter.
You can ask me directly here.

Adobe Air - User preferences XML

I need to create and read a user preferences XML file with Adobe Air. It will contain around 30 nodes.
<id>18981</id>
<firstrun>false</firstrun>
<background>green</background>
<username>stacker</username>
...
What's a good method to do this?
Write up an "XML parser" that reads the values and is aware of the data types to convert to based on the "save preferences model." So basically you write a method/class for writing the data from the "save preferences model" to XML then write a method/class for reading from the XML into the "save preferences model", you can use describeType for both. Describe type will return an XML description of the model classes properties and the types of those properties and accessibility (read/write, readonly, write only). For all properties that are read/write you would store them into the XML output, when reading them back in you would do the same thing except you could use the type property from the describeType output to determine if you need to do a string to boolean conversion (if(boolValue == "true")) and string to number conversions, parseInt or parseFloat. You could ultimately store the XML in a local SQL database if you want to keep history, or else just store the current preferences in flat file (using FileReference, or in AIR you can use FileStream to write directly to a location).
Edit:
Agree with Joshua's comment below local shared objects was the first thing I thought of when seeing this, you can eliminate the need to write the XML parser/reader since it will handle serializing/de-serializing the objects for you (but manually looking at the LSO is probably ugly)... anyhow I had done something similar for another project of mine, I tried stripping out the relevant code, to note in my example here I didn't use describe type but the general concept is the same:
http://shaunhusain.com/OnePageSaverLoader/index.php

Setting the output file name in a biztalk send port

Good afternoon,
I'm trying to set the output file name in a send port and the available file name macros won't quite work.
I need something of the form "file.YYYYMMDD_HHMMSS". There's a datetime combined macro (with the wrong format), a time only macro, but no date only macro.
I don't have an orchestration for this process.
Is there any way I can set the file name from within a map or a pipeline?
Thanks!
You can achieve filename in this format YYYYMMDD_HHMMSS using following.
Use expression shape in orchestration and create four variables.
varDateTime=System.DateTime.Now; //varDateTime is datetime type
strDate=varDateTime.ToString("yyyyMMdd"); //strDate is string type
strTime=varDateTime.ToString("HHmmss"); //strTime is string type
outboundfilename= ""+strDate + " _ " +strTime +" "; //outboundfilename is the string variable.
Use the following code in Message Assignment Shape
msgOutbound(FILE.ReceivedFileName)=outboundfilename+".xml";
//File extension can be any based on your requirement. I have xml file type.
You don't need custom pipeline to do this.
You can do it with a custom pipeline or an orchestration but not with a map. Info on building a custom pipeline can be found here:
BizTalk MSDN Blogs
This can be set by setting the FILE.ReceivedFileName (instead of BTS.ReceiveFileName).
You can create a custom pipeline component to be placed on the send side (say encode stage), and then set the BTS.ReceiveFileName property to the custom file name value that needs to be set.
After this is done, you can use the %SourceFileName% macro in the Send Port. You can also refer to this MSDN forum link for more details

check uploaded file in vb.net

I need a snippet to check file for validity (I'm allowing users to upload xml files). So I need to check whether uploaded file is XML.
The best I can think of is just check if extension is ".xml". What if its replaced?
You can try loading it like this and catch the exception:
XDocument xdoc = XDocument.Load("data.xml"));
Presumably, if they're uploading XML, then you're going to use it for something afterwards. In this case you should validate the XML against a Schema (XSD etc) so that you know you aren't going to hit unexpected values/layouts etc.
In Urlmon.dll, there's a function called FindMimeFromData.
From the documentation
MIME type detection, or "data
sniffing," refers to the process of
determining an appropriate MIME type
from binary data. The final result
depends on a combination of
server-supplied MIME type headers,
file extension, and/or the data
itself. Usually, only the first 256
bytes of data are significant.
So, read the first (up to) 256 bytes from the file and pass it to FindMimeFromData.
If you must validate the xml (assuming you want to validate the entire thing) you can use the XmlDocument class and catch an exception if it's not XML.

Getting extension of the file in FileUpload Control

At the moment i get file extension of the file like :
string fileExt = System.IO.Path.GetExtension(filUpload.FileName);
But if the user change the file extension of the file ( for example user could rename "test.txt" to "test.jpg" ), I can't get the real extension . What's the solution ?
You seem to be asking if you can identify file-type from its content.
Most solutions will indeed attempt the file extension, but there are too many different possible file types to be reliably identifiable.
Most approaches use the first several bytes of the file to determine what they are.
Here is one list, here another.
If you are only worried about text vs binary, see this SO question and answers.
See this SO answer for checking if a file is a JPG - this approach can be extended to use other file headers as in the first two links in this answer.
Whatever the user renames the file extension to, that is the real file extension.
You should never depend on the file extension to tell you what's in the file, since it can be renamed.
See "how can we check file types before uploading them in asp.net?"
There's no way to get the 'real' file extension - the file extension that you get from the filename is the real one. If file content is your concern, you can retrieve the content type using the .ContentType property and verify that it is a content type that you are expecting - eg. image/jpg.

Resources