public static string CanonicalizePathIfLocalAndExists(this string filename) { if (string.IsNullOrEmpty(filename)) { return null; } try { var fullpath = filename.CanonicalizePath(); if (!fullpath.StartsWith(@"\\") && File.Exists(fullpath)) { return fullpath; } } catch { } return null; }
public static string EnsureFileIsLocal(this string filename, string localFolder = null) { localFolder = localFolder ?? TempPath; var fullpath = filename.CanonicalizePath(); if (File.Exists(fullpath)) { if (fullpath.StartsWith(@"\\")) { var localCopy = Path.Combine(localFolder, Path.GetFileName(fullpath)); File.Copy(fullpath, localCopy); return localCopy; } return fullpath; } return null; }