/// <summary>Gets all available Verbs (contextmenu items) for a given filetype or folder as Array. /// Applying of a Verb on file/folder under see 'ApplyVerbOn'.</summary> /// <param name="path">The full file- or folder path.</param> /// <returns>All available Verbs as Array ("idx=verb;...", w/o '&') on success, else "FAILED".</returns> public static Primitive GetAllVerbsFor(Primitive path) { string fo = Environment.ExpandEnvironmentVariables(path); if (!System.IO.File.Exists(fo) && !Directory.Exists(fo)) { return("FAILED"); } char[] charsTrim = { ' ', '\'' }; fo = fo.Trim(charsTrim); string fDir = Path.GetDirectoryName(fo); string fNameExt = Path.GetFileName(fo); Primitive result = new Primitive(); try { Shell32.Folder fold = GetShell32NameSpace(fDir); Shell32.FolderItem foldItem = fold.ParseName(fNameExt); Shell32.FolderItemVerbs verbs = foldItem.Verbs(); for (int i = 0; i < verbs.Count; i++) { Shell32.FolderItemVerb vrb = verbs.Item(i); string verbName = vrb.Name.Replace(@"&", string.Empty); if (verbName.Length > 0) { result[result.GetItemCount() + 1] = verbName; } } return(result); } catch { return("FAILED"); } }
/// <summary>Apply the given Verb (contextmenu item) for the given file or folder. /// List of available Verbs (for a filetype or folder) under 'GetAllVerbsFor'.</summary> /// <param name="path">The full file- or folder path.</param> /// <param name="verb">The Verb to apply (case- and '&' insensitive).</param> /// <returns>"SUCCESS" on success, else "FAILED".</returns> public static Primitive ApplyVerbOn(Primitive path, Primitive verb) { string vUse = verb; if (vUse.Length == 0) { return("FAILED"); } vUse = vUse.Replace(@"&", string.Empty).ToLower(); string fo = Environment.ExpandEnvironmentVariables(path); if (!System.IO.File.Exists(fo) && !Directory.Exists(fo)) { return("FAILED"); } char[] charsTrim = { ' ', '\'' }; fo = fo.Trim(charsTrim); string fDir = Path.GetDirectoryName(fo); string fNameExt = Path.GetFileName(fo); try { Shell32.Folder fold = GetShell32NameSpace(fDir); Shell32.FolderItem foldItem = fold.ParseName(fNameExt); Shell32.FolderItemVerbs verbs = foldItem.Verbs(); for (int i = 0; i < verbs.Count; i++) { Shell32.FolderItemVerb vrb = verbs.Item(i); string verbName = vrb.Name.Replace(@"&", string.Empty).ToLower(); if (verbName.Equals(vUse)) { vrb.DoIt(); return("SUCCESS"); } } return("FAILED"); } catch { return("FAILED"); } }