Illegal characters in path

Jul 13, 2011 at 11:22 AM



I'm having a problem with 1 of 40 ports when testing this your pipeline. Getting this error:

<EventData>    <Data>Illegal characters in path.   at System.Security.Permissions.FileIOPermission.HasIllegalCharacters(String[] str)   at System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess access, AccessControlActions control, String[] pathListOrig, Boolean checkForDuplicates, Boolean needFullPath, Boolean copyPathList)   at System.Security.Permissions.FileIOPermission..ctor(FileIOPermissionAccess access, AccessControlActions control, String[] pathList, Boolean checkForDuplicates, Boolean needFullPath)   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath)   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access)   at SAB.BizTalk.Pipeline.Components.Archiving.SABArchiving.Execute(IPipelineContext pc, IBaseMessage inmsg)</Data>  </EventData>


I don't understand why I'm getting the message as both the filenames and paths are almost identical (2 ports that picks files from the same location but one picking  LIK*.xml and the other LIR*.xml).  Both receive ports have the identical settings for the pipeline.

Is it possible to add some code to make the pipeline more robust?  Like strip illegal characters?   I found some code that might work:

string regex = String.Format("[{0}]", Regex.Escape(new string(Path.GetInvalidFileNameChars())));Regex removeInvalidChars = new Regex(regex, RegexOptions.Singleline | RegexOptions.Compiled |RegexOptions.CultureInvariant);

And then use:



But quite sure where to add it in your pipeline.    Also if possible, can you catch this type of exception specifically and add the path information to the eventlog error message? That way it's easier to check what's wrong in the path or filename.

Thanks :)

Jul 13, 2011 at 11:41 AM

Forgot to add that the file-path gets created ok at the archive location, but the file is not put there..  (Using the macros %Year% and %Month%).

Jul 14, 2011 at 12:09 PM


I am hoping to be able to make some changes to the component soon, but due to work pressures this may not be for a few weeks.  At this time I'll aim to take a look at your suggestions and see what can be done.

Thanks for the feedback, its always useful to know what issues other users are coming across.




Jul 21, 2011 at 8:19 AM

Thanks Stu!

Looking forward to the next revision :)

Sep 20, 2011 at 2:30 PM


A quick followup.  I actually had entered a  "*.xml"  in the filemask on the port I had problems with instead of just  ".xml", so my bad ;-)    Long days at work and too many ports to configure.. lol..


Anyways, some quick code to check the user-entered data would be excellent :-)    Either to notify the user of his mistake or just do an auto-cleanup using something like the code below:


private static string CleanFileName(string fileName)
return Path.GetInvalidFileNameChars().Aggregate(fileName, (current, c) => current.Replace(c.ToString(), " "));





Sep 20, 2011 at 2:40 PM


Also adding something like a variable: "string PortName;" below "const int bufferSize = 1024;"   and add the portname to it so that you could add the information in the "System.Diagnostics.EventLog.WriteEntry..." output.  Much easier to debug and correct your configuration problems later on.