Comment déterminer si un chemin de répertoire était SUBST’d

Comment puis-je savoir si un fichier se trouve dans un dossier qui a été soumis ou est situé dans un dossier utilisateur à l’aide de C #?

Je pense que vous devez P / Invoke QueryDosDevice () pour la lettre de lecteur. Les lecteurs Subst retournent un lien symbolique, similaire à \ ?? \ C: \ blah. Le préfixe \ ?? \ indique qu’il est substitué, le rest vous donne le lecteur + répertoire.

Je pense que vous avez quelques choix –

Via les classes System.Management: http://briancaos.wordpress.com/2009/03/05/get-local-path-from-unc-path/

Ou

Via P / Invocation de cette fonction MAPI: ScUNCFromLocalPath http://msdn.microsoft.com/en-us/library/cc842520.aspx

Si SUBST est exécuté sans paramètre, il génère une liste de toutes les substitutions actuelles. Obtenez la liste et vérifiez votre répertoire par rapport à la liste.

Il y a aussi la question du mappage d’un volume sur un répertoire. Je n’ai jamais essayé de les détecter, mais les répertoires des points de assembly ne s’affichent pas de la même manière que les répertoires classiques. Ils doivent donc avoir un atsortingbut différent, ce qui pourrait être détecté.

C’est le code que j’utilise pour obtenir les informations si un chemin est défini: (Certaines parties proviennent de pinvoke )

 [DllImport("kernel32.dll", SetLastError=true)] static extern uint QueryDosDevice(ssortingng lpDeviceName, SsortingngBuilder lpTargetPath, int ucchMax); public static bool IsSubstedPath(ssortingng path, out ssortingng realPath) { SsortingngBuilder pathInformation = new SsortingngBuilder(250); ssortingng driveLetter = null; uint winApiResult = 0; realPath = null; try { // Get the drive letter of the path driveLetter = Path.GetPathRoot(path).Replace("\\", ""); } catch (ArgumentException) { return false; //<------------------ } winApiResult = QueryDosDevice(driveLetter, pathInformation, 250); if(winApiResult == 0) { int lastWinError = Marshal.GetLastWin32Error(); // here is the reason why it fails - not used at the moment! return false; //<----------------- } // If drive is substed, the result will be in the format of "\??\C:\RealPath\". if (pathInformation.ToString().StartsWith("\\??\\")) { // Strip the \??\ prefix. string realRoot = pathInformation.ToString().Remove(0, 4); // add backshlash if not present realRoot += pathInformation.ToString().EndsWith(@"\") ? "" : @"\"; //Combine the paths. realPath = Path.Combine(realRoot, path.Replace(Path.GetPathRoot(path), "")); return true; //<-------------- } realPath = path; return false; }