Reputation: 1440
if (System.IO.Path.GetExtension(message).ToLower() == "mp4")
The above statement throws an argument exception that is baffling me as the error "Invalid Characters in Path" seems wrong in the context that message is equal to this:
string message = @"D:\Cases\Case 0\Records\Videos\VID_2014_1222163200_0.MP4"
I can't seem to find the invalid character!
BitConverter.ToString(Encoding.Unicode.GetBytes(message))
Will return this:
12/23/2014-4:06:14 PM: ERROR: 44-00-3A-00-5C-00-43-00-61-00-73-00-65-00-73-00-5C-00-43-00-61-00-73-00-65-00-20-00-30-00-5C-00-52-00-65-00-63-00-6F-00-72-00-64-00-73-00-5C-00-56-00-69-00-64-00-65-00-6F-00-73-00-5C-00-56-00-49-00-44-00-5F-00-32-00-30-00-31-00-34-00-5F-00-31-00-32-00-32-00-32-00-31-00-36-00-33-00-32-00-30-00-30-00-5F-00-30-00-2E-00-4D-00-50-00-34-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
Upvotes: 1
Views: 1609
Reputation: 48726
Use this single line of code and it should return to you the index number of the invalid character (0-based). If it returns anything < 0
, then there are no invalid characters in your path.
int ndx = message.IndexOfAny(System.IO.Path.GetInvalidPathChars());
Upvotes: 1
Reputation: 39520
There's no exception problem with the code as copied from your question.
Sometimes hard-to-spot invalid characters in string literals come from cutting and pasting from things like web browsers into code. If I were you, I would re-type the literal by hand.
The function throwing this exception has a test which looks like this:
if (c == '\"' || c == '<' || c == '>' || c == '|' || c < 32)
Knowing this might give you some clue what's wrong.
Update:
Following the comments which reveal that the original code example is not reflective of the application, I'd suggest you add a .Trim()
call:
if (Path.GetExtension(message.Trim()).Equals(".mp4",
StringComparison.OrdinalIgnoreCase))
(I've also fixed the .mp4 string and the comparison for you.)
Upvotes: 1