File path (contains special characters) problem when passing as input to API function.

  • Thread starter Thread starter Sakharam Phapale
  • Start date Start date
S

Sakharam Phapale

Hi All,

I am using an API function, which takes file path as an input.
When file path contains special characters (@,#,$,%,&,^, etc), API function
gives an error as "Unable to open input file".
Same file path containing special characters works fine in one machine, but
doesn't work in other.
I am using following API function to get short file path.

Declare Auto Function GetShortPathName Lib "kernel32" (ByVal lpszLongPath As
String, ByVal lpszShortPath As System.Text.StringBuilder, ByVal cchBuffer As
Integer) As Integer
Using this I get expected result for most of the time. Bu still in some
combinations I get error. e.g. when file is in "D:\Bin$\hello.wav"

Please, can anyone give me some details about this problem and how to solve
it.

Thanks in Advance.

Sakharam Phapale
 
Why are you using this function?
If you have this:
string path = "c:\\folder1\forder2\file.exe"
Extract the short path by:
string ShortPath = path.Substring(s.LastIndexOf("\\" + 1));
 
Back
Top