Friday, October 15, 2010 11:35 AM
Stop using String to parse file paths
As I move around between different customers I see a lot of different takes on architecture and solutions regarding BizTalk. However there is one thing that never, ever, changes. Programmers use string classes to parse file paths. Stop that! It is usually inefficient but most of all very ugly.
The case tend to be that you need the filename, because you stored some kind of information in it, like a transaction ID.
Here is how it usually looks:
ID = MessageName(FILE.ReceiveFileName)
ID = ID.Remove(0, ID.LastIndexOf(@"\") + 1);
transID = ID.Replace(".xml", "" );
Now here is the nicer and better way to do it:
transID = System.IO.Path.GetFileNameWithoutExtension
Here are a list of useful static functions to use within your next Expression- or Assign shape:
GetFileName, GetExtention, GetDirectoryName, GetFullPath, GetPathRoot, GetFullPath, GetInvalidFileNameChars, GetInvalidPathChars.
The last two are especially useful when you generate filenames based on message data, since these tend to contain chars like ‘:’ or ‘?’.
Filed under: Biztalk, Coding