BExplorer.Shell.Interop.User32.PinUnpinToTaskbar C# (CSharp) Method

PinUnpinToTaskbar() public static method

public static PinUnpinToTaskbar ( string filePath ) : void
filePath string
return void
		public static void PinUnpinToTaskbar(string filePath) {
			//PinUnpinTaskbar(filePath, !IsPinnedToTaskbar(filePath));
			var pin = IsPinnedToTaskbar(filePath);

			if (!File.Exists(filePath)) throw new FileNotFoundException(filePath);

			// create the shell application object
			dynamic shellApplication = Activator.CreateInstance(Type.GetTypeFromProgID("Shell.Application"));

			string path = Path.GetDirectoryName(filePath);
			string fileName = Path.GetFileName(filePath);

			dynamic directory = shellApplication.NameSpace(path);
			dynamic link = directory.ParseName(fileName);

			dynamic verbs = link.Verbs();
			for (int i = 0; i < verbs.Count(); i++) {
				dynamic verb = verbs.Item(i);
				string verbName = verb.Name.Replace("&", string.Empty).ToLower();

				if ((pin && verbName.Equals(LoadResourceString(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "shell32.dll"), 5386, "pin to taskbar").Replace("&", string.Empty).ToLower()))
				|| (!pin && verbName.Equals(LoadResourceString(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "shell32.dll"), 5387, "unpin from taskbar").Replace("&", string.Empty).ToLower()))
				) {
					verb.DoIt();
				}
			}
		}