c# - `FileNotFoundException` for network-shared files that do exist. What am I missing? -
i need default file icon shared file. faced problems , found the question "how associated icon network share file".
but have problem shared files, looks if did not exist. here code:
public static icon extractassociatedicon(string filepath) { int index = 0; uri uri; if (filepath == null) { throw new argumentexception(string.format("'{0}' not valid '{1}'", "null", "filepath"), "filepath"); } try { uri = new uri(filepath); } catch (uriformatexception) { filepath = path.getfullpath(filepath); uri = new uri(filepath); } if (uri.isfile) { if (!file.exists(filepath)) { throw new filenotfoundexception(filepath); } stringbuilder iconpath = new stringbuilder(260); iconpath.append(filepath); intptr handle = safenativemethods.extractassociatedicon(new handleref(null, intptr.zero), iconpath, ref index); if (handle != intptr.zero) { return icon.fromhandle(handle); } } return null; }
i filenotfoundexception
, don't why. filepath
ok, , can access these files through explorer. tried create fileinfo
instance filepath
(i read somewhere may help) still nothing.
what i'm missing?
iirc, file.exists
, directory.exists
have problems resolving drive letters mapped network share. might not see these drives, report false
though path points valid file.
if use unc paths (\\server\share\file.name
) instead of drive letters, might work, resolve drive-letter-bassed file path unc path first , pass latter file.exists
. see e.g. this answer that question example how this.
Comments
Post a Comment